Skip to content

Commit 23c1b83

Browse files
committed
fix tests
1 parent 20c1caf commit 23c1b83

File tree

6 files changed

+32
-23
lines changed

6 files changed

+32
-23
lines changed

OpenUtau.Core/Classic/ClassicSinger.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,24 @@ public ClassicSinger(Voicebank voicebank) {
4747
}
4848

4949
public override void EnsureLoaded() {
50+
EnsureLoaded(false);
51+
}
52+
public void EnsureLoaded(bool isTest) {
5053
if (Loaded) {
5154
return;
5255
}
53-
Reload();
56+
Reload(isTest);
5457
}
5558

5659
public override void Reload() {
60+
Reload(false);
61+
}
62+
private void Reload(bool isTest) {
5763
if (!Found) {
5864
return;
5965
}
6066
try {
61-
voicebank.Reload();
67+
voicebank.Reload(isTest);
6268
Load();
6369
loaded = true;
6470
if (otoWatcher == null) {

OpenUtau.Core/Classic/VoiceBank.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class Voicebank {
2525
public string Id;
2626

2727
public void Reload() {
28+
Reload(false);
29+
}
30+
public void Reload(bool isTest) {
2831
Name = null;
2932
Image = null;
3033
Portrait = null;
@@ -40,7 +43,7 @@ public void Reload() {
4043
OtoSets.Clear();
4144
Subbanks.Clear();
4245
Id = null;
43-
VoicebankLoader.LoadVoicebank(this);
46+
VoicebankLoader.LoadVoicebank(this, isTest);
4447
}
4548

4649
public override string ToString() {

OpenUtau.Core/Classic/VoicebankErrorChecker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void Check() {
6060
});
6161
}
6262
try {
63-
VoicebankLoader.LoadVoicebank(voicebank);
63+
VoicebankLoader.LoadVoicebank(voicebank, false);
6464
} catch (Exception e) {
6565
Errors.Add(new VoicebankError() {
6666
message = "Failed to load voicebank",

OpenUtau.Core/Classic/VoicebankLoader.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public IEnumerable<Voicebank> SearchAll() {
5757
return result;
5858
}
5959

60-
public static void LoadVoicebank(Voicebank voicebank) {
60+
public static void LoadVoicebank(Voicebank voicebank, bool isTest) {
6161
LoadInfo(voicebank, voicebank.File, voicebank.BasePath);
62-
LoadOtoSets(voicebank, Path.GetDirectoryName(voicebank.File));
62+
LoadOtoSets(voicebank, Path.GetDirectoryName(voicebank.File), isTest);
6363
}
6464

65-
public static void LoadOtoSets(Voicebank voicebank, string dirPath) {
65+
public static void LoadOtoSets(Voicebank voicebank, string dirPath, bool isTest) {
6666
var otoFile = Path.Combine(dirPath, kOtoIni);
6767
if (File.Exists(otoFile)) {
68-
var otoSet = ParseOtoSet(otoFile, voicebank.TextFileEncoding);
68+
var otoSet = ParseOtoSet(otoFile, voicebank.TextFileEncoding, isTest);
6969
var voicebankDir = Path.GetDirectoryName(voicebank.File);
7070
otoSet.Name = Path.GetRelativePath(voicebankDir, dirPath);
7171
if (otoSet.Name == ".") {
@@ -75,7 +75,7 @@ public static void LoadOtoSets(Voicebank voicebank, string dirPath) {
7575
}
7676
var dirs = Directory.GetDirectories(dirPath);
7777
foreach (var dir in dirs) {
78-
LoadOtoSets(voicebank, dir);
78+
LoadOtoSets(voicebank, dir, isTest);
7979
}
8080
}
8181

@@ -288,10 +288,10 @@ public static Dictionary<Tuple<string, string>, SortedSet<int>> ParsePrefixMap(S
288288
}
289289
}
290290

291-
public static OtoSet ParseOtoSet(string filePath, Encoding encoding) {
291+
public static OtoSet ParseOtoSet(string filePath, Encoding encoding, bool isTest) {
292292
try {
293293
using (var stream = File.OpenRead(filePath)) {
294-
var otoSet = ParseOtoSet(stream, filePath, encoding);
294+
var otoSet = ParseOtoSet(stream, filePath, encoding, isTest);
295295
AddAliasForMissingFiles(otoSet);
296296
return otoSet;
297297
}
@@ -301,7 +301,7 @@ public static OtoSet ParseOtoSet(string filePath, Encoding encoding) {
301301
return null;
302302
}
303303

304-
public static OtoSet ParseOtoSet(Stream stream, string filePath, Encoding encoding) {
304+
public static OtoSet ParseOtoSet(Stream stream, string filePath, Encoding encoding, bool isTest) {
305305
OtoSet otoSet;
306306
using (var reader = new StreamReader(stream, encoding)) {
307307
var trace = new FileTrace { file = filePath, lineNumber = 0 };
@@ -312,7 +312,7 @@ public static OtoSet ParseOtoSet(Stream stream, string filePath, Encoding encodi
312312
var line = reader.ReadLine().Trim();
313313
trace.line = line;
314314
try {
315-
Oto oto = ParseOto(line, trace);
315+
Oto oto = ParseOto(line, trace, isTest);
316316
if (oto != null) {
317317
otoSet.Otos.Add(oto);
318318
}
@@ -346,7 +346,7 @@ static void AddAliasForMissingFiles(OtoSet otoSet) {
346346
}
347347
}
348348

349-
static Oto ParseOto(string line, FileTrace trace) {
349+
static Oto ParseOto(string line, FileTrace trace, bool isTest) {
350350
const string format = "<wav>=<alias>,<offset>,<consonant>,<cutoff>,<preutter>,<overlap>";
351351
var oto = new Oto {
352352
FileTrace = new FileTrace(trace),
@@ -386,13 +386,13 @@ static Oto ParseOto(string line, FileTrace trace) {
386386
oto.Error = $"{trace}\nFailed to parse overlap. Format is {format}.";
387387
return oto;
388388
}
389-
#if DEBUG == false
390-
string path = Path.Combine(Path.GetDirectoryName(trace.file), oto.Wav);
391-
if (!File.Exists(path)) {
392-
oto.Error = $"{trace}\nSound file missing. {path}";
393-
return oto;
389+
if (!isTest) {
390+
string path = Path.Combine(Path.GetDirectoryName(trace.file), oto.Wav);
391+
if (!File.Exists(path)) {
392+
oto.Error = $"{trace}\nSound file missing. {path}";
393+
return oto;
394+
}
394395
}
395-
#endif
396396
oto.IsValid = true;
397397
return oto;
398398
}

OpenUtau.Test/Classic/VoicebankLoaderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void OtoSetRoundTrip() {
3939
".Replace("\r\n", "\n");
4040

4141
using (MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(text))) {
42-
var otoSet = VoicebankLoader.ParseOtoSet(stream, "oto.ini", Encoding.ASCII);
42+
var otoSet = VoicebankLoader.ParseOtoSet(stream, "oto.ini", Encoding.ASCII, true);
4343
using (MemoryStream stream2 = new MemoryStream()) {
4444
VoicebankLoader.WriteOtoSet(otoSet, stream2, Encoding.ASCII);
4545
string actual = Encoding.ASCII.GetString(stream2.ToArray());

OpenUtau.Test/Plugins/PhonemizerTestBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public void RunPhonemizeTest(string singerName, string[] lyrics, string[] alts,
2626
var file = Path.Join(basePath, singerName, "character.txt");
2727

2828
var voicebank = new Voicebank() { File = file, BasePath = dir };
29-
VoicebankLoader.LoadVoicebank(voicebank);
29+
VoicebankLoader.LoadVoicebank(voicebank, true);
3030
var singer = new ClassicSinger(voicebank);
31-
singer.EnsureLoaded();
31+
singer.EnsureLoaded(true);
3232

3333
var timeAxis = new Core.TimeAxis();
3434
timeAxis.BuildSegments(new Core.Ustx.UProject());

0 commit comments

Comments
 (0)