Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
Work for #120

CI build has been broken for a while, but thanks to 664aba0 it now works again and broken tests were found.
  • Loading branch information
atruskie committed Nov 28, 2017
1 parent 8c3df1e commit b3a37f2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Acoustics/Acoustics.Shared/ConfigFile/ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Acoustics.Shared.ConfigFile
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -175,6 +176,12 @@ public static bool TryResolveConfigFile(string file, IEnumerable<DirectoryEntry>
return true;
}

if (Path.IsPathRooted(file))
{
// if absolute on concrete file system and can't be found then we can't resolve automatically
return false;
}

if (searchPaths != null)
{
foreach (var directory in searchPaths)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void ClassInitialize(TestContext context)
{
// calculate indices
var recordingPath = PathHelper.ResolveAsset("Recordings", "OxleyCreek_site_1_1060_244333_20140529T081358+1000_120_0.wav");
var configPath = PathHelper.ResolveConfigFile("Towsey.Acoustic.HiRes.yml");
var configPath = PathHelper.ResolveConfigFile("Towsey.Acoustic.Zooming.yml");
var arguments = new AnalyseLongRecording.Arguments
{
Source = recordingPath,
Expand Down Expand Up @@ -70,13 +70,13 @@ public static void ClassInitialize(TestContext context)
[TestMethod]
public void TestGenerateTilesFailsWithInvalidScales()
{
PathHelper.ResolveConfigFile("IndexPropertiesConfig.HiRes.yml").CopyTo(this.outputDirectory.CombineFile("IndexPropertiesConfig.HiRes.yml").FullName);
PathHelper.ResolveConfigFile("IndexPropertiesConfig.Zooming.yml").CopyTo(this.outputDirectory.CombineFile("IndexPropertiesConfig.Zooming.yml").FullName);

void SetupAndRun(params double[] scales)
{
SpectrogramZoomingConfig config = new SpectrogramZoomingConfig();
config.SpectralIndexScale = scales;
config.IndexPropertiesConfig = ".\\IndexPropertiesConfig.HiRes.yml";
config.IndexPropertiesConfig = ".\\IndexPropertiesConfig.Zooming.yml";

var newConfigFile = this.outputDirectory.CombineFile("SpectrogramZoomingConfig.yml");
Yaml.Serialise(newConfigFile, config);
Expand Down
12 changes: 12 additions & 0 deletions Acoustics/Acoustics.Test/Shared/ConfigFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ public void TheResolveMethodThrows()
string config = "doesNotExist.yml";

Assert.Throws<ConfigFileException>(() => { ConfigFile.ResolveConfigFile(config); });
Assert.Throws<ConfigFileException>(
() => { ConfigFile.ResolveConfigFile(config, Environment.CurrentDirectory.ToDirectoryInfo()); });
}

[TestMethod]
public void TheResolveMethodThrowsAbsolute()
{
string config = "C:\\doesNotExist.yml";

Assert.Throws<ConfigFileException>(() => { ConfigFile.ResolveConfigFile(config); });
Assert.Throws<ConfigFileException>(
() => { ConfigFile.ResolveConfigFile(config, Environment.CurrentDirectory.ToDirectoryInfo()); });
}

[TestMethod]
Expand Down
11 changes: 11 additions & 0 deletions AudioAnalysis/AnalysisBase/FileSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ public FileSegment(FileInfo source, int sampleRate, TimeSpan duration, FileDateB
Contract.Ensures(this.Validate(), "FileSegment did not validate");
}

/// <summary>
/// Initializes a new instance of the <see cref="FileSegment"/> class.
/// Allow specifying an absolutely aligned (to the nearest minute) file segment.
/// Implies `FileDateBehavior.Required`.
/// NOTE: Start offset will be set to start of file, and end offset set to the end of the file.
/// </summary>
public FileSegment(FileInfo source, TimeAlignment alignment)
: this(source, alignment, null, FileDateBehavior.Required)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="FileSegment"/> class.
/// Allow specifying an absolutely aligned (to the nearest minute) file segment.
Expand Down

0 comments on commit b3a37f2

Please sign in to comment.