Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked PDPs to enable layering PDPs, added platform.base, added Scripture extender layering PDP, replaced name from ProjectMetadata with project setting platform.name #930

Merged
merged 12 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
"%settings_platform_interfaceLanguage_label%": "Interface Language",
"%project_settings_platform_group1_label%": "Platform Settings",
"%project_settings_platform_group1_description%": "Project settings pertaining to the software overall",
"%project_settings_platform_name_label%": "Project Short Name",
"%project_name_missing%": "_NoName_",
"%project_settings_platform_fullName_label%": "Project Full Name",
"%project_full_name_missing%": "*Name Missing*",
"%project_settings_platform_language_label%": "Project Primary Language",
"%project_settings_platform_isEditable_label%": "Is Editable",
"%project_settings_platform_isEditable_description%": "Whether this project is editable. A project that is not editable is sometimes called a resource."
Expand Down
6 changes: 4 additions & 2 deletions c-sharp-tests/DummyLocalParatextProjects.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System.Diagnostics.CodeAnalysis;
using Paranext.DataProvider.Projects;
using Paratext.Data;

namespace TestParanextDataProvider
{
[ExcludeFromCodeCoverage]
internal class DummyLocalParatextProjects : LocalParatextProjects
{
public void FakeAddProject(ProjectDetails details)
public void FakeAddProject(ProjectDetails details, ScrText? scrText = null)
{
_projectDetailsMap[details.Metadata.ID] = details;
scrText ??= new DummyScrText(details);
ScrTextCollection.Add(scrText, true);
}

public override void Initialize(bool shouldIncludePT9ProjectsOnWindows)
Expand Down
104 changes: 77 additions & 27 deletions c-sharp-tests/DummyScrText.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Xml;
using Paranext.DataProvider.Projects;
using Paratext.Data;
using Paratext.Data.Languages;
using Paratext.Data.ProjectFileAccess;
Expand All @@ -15,18 +16,29 @@ internal class DummyScrText : ScrText
{
private readonly HexId _id;

public DummyScrText() : base(RegistrationInfo.DefaultUser)
public DummyScrText(ProjectDetails projectDetails)
: base(
new ProjectName
{
ShortName = projectDetails.Name,
ProjectPath = projectDetails.HomeDirectory
},
RegistrationInfo.DefaultUser
)
{
_id = HexId.CreateNew();
projectName = new ProjectName();
projectName.ShortName = "Dummy" + _id;
_id = HexId.FromStr(projectDetails.Metadata.ID);
projectName = new ProjectName
{
ShortName = projectDetails.Name + _id,
ProjectPath = projectDetails.HomeDirectory
};

Settings.Editable = true;
Settings.UsfmVersion = UsfmVersionOption.Version3;

cachedDefaultStylesheet.Set(new DummyScrStylesheet());
cachedFrontBackStylesheet.Set(cachedDefaultStylesheet);

LanguageId langId = new("dmy", null, null, null);
DummyScrLanguage language = new(this);
language.SetLanguageId(langId);
Expand All @@ -36,6 +48,15 @@ public DummyScrText() : base(RegistrationInfo.DefaultUser)
language.ForceSaveLdml(this);
}

public DummyScrText()
: this(
new ProjectDetails(
"Dummy",
new ProjectMetadata(HexId.CreateNew().ToString(), []),
""
)
) { }

protected override void Load(bool ignoreLoadErrors = false)
{
// Nothing to do
Expand All @@ -45,15 +66,16 @@ protected override ProjectFileManager CreateFileManager()
{
return new InMemoryFileManager(this);
}

protected override ProjectSettings CreateProjectSettings(bool ignoreFileMissing)
{
ProjectSettings settings = new(this, true)
{
FullName = "Test ScrText",
MinParatextDataVersion = ParatextInfo.MinSupportedParatextDataVersion,
Guid = _id
};
ProjectSettings settings =
new(this, true)
{
FullName = "Test ScrText",
MinParatextDataVersion = ParatextInfo.MinSupportedParatextDataVersion,
Guid = _id
};

return settings;
}
Expand All @@ -64,9 +86,8 @@ private sealed class InMemoryFileManager : ProjectFileManager
private static readonly Encoding s_utf8NoBOM = new UTF8Encoding(false);
private readonly Dictionary<string, InMemoryFile> _fileSystem = new();

public InMemoryFileManager(ScrText scrText) : base(scrText)
{
}
public InMemoryFileManager(ScrText scrText)
: base(scrText) { }

// Implementation shamelessly stolen from the Paratext test code and then simplified

Expand All @@ -85,7 +106,9 @@ public override void Delete(string relFilePath)

public override void DeleteDirectory(string relDirPath)
{
string[] filesToBeRemoved = _fileSystem.Keys.Where(k => Path.GetDirectoryName(k) == relDirPath).ToArray();
string[] filesToBeRemoved = _fileSystem
.Keys.Where(k => Path.GetDirectoryName(k) == relDirPath)
.ToArray();
foreach (string file in filesToBeRemoved)
Delete(file);
}
Expand All @@ -102,22 +125,35 @@ public override void CopyFile(string absSourceFilePath, string dstRelPath)
throw new NotImplementedException();
}

public override IEnumerable<string> ProjectFiles(string searchPattern, string? relDirPath = null)
public override IEnumerable<string> ProjectFiles(
string searchPattern,
string? relDirPath = null
)
{
return Enumerable.Empty<string>();
}

public override IEnumerable<string> ProjectDirectories(string searchPattern, string? relDirPath = null)
public override IEnumerable<string> ProjectDirectories(
string searchPattern,
string? relDirPath = null
)
{
return Enumerable.Empty<string>();
}

public override void WriteFileCreatingBackup(string relFilePath, Action<string> writeFile, Action<string>? validateFile = null)
public override void WriteFileCreatingBackup(
string relFilePath,
Action<string> writeFile,
Action<string>? validateFile = null
)
{
writeFile(relFilePath);
}

public override TextReader OpenFileForRead(string relFilePath, Encoding? encoding = null)
public override TextReader OpenFileForRead(
string relFilePath,
Encoding? encoding = null
)
{
// ENHANCE: Keep track of file locking via a custom reader to further increase testing accuracy.
if (encoding == null)
Expand All @@ -136,7 +172,10 @@ public override XmlTextReader OpenFileForXmlRead(string relFilePath)
return new XmlTextReader(new MemoryStream(GetFile(relFilePath)));
}

public override TextWriter OpenFileForWrite(string relFilePath, Encoding? encoding = null)
public override TextWriter OpenFileForWrite(
string relFilePath,
Encoding? encoding = null
)
{
if (encoding == null)
encoding = s_utf8NoBOM;
Expand All @@ -150,7 +189,9 @@ public override BinaryWriter OpenFileForByteWrite(string relFilePath)

public override void SetXml<T>(T obj, string relFilePath)
{
_fileSystem[relFilePath] = new InMemoryFile(s_utf8NoBOM.GetBytes(Memento.ToXmlString(obj)));
_fileSystem[relFilePath] = new InMemoryFile(
s_utf8NoBOM.GetBytes(Memento.ToXmlString(obj))
);
}

public override T GetXml<T>(string relFilePath)
Expand Down Expand Up @@ -203,8 +244,12 @@ private sealed class DummyStreamWriter : StreamWriter
private readonly InMemoryFileManager _owner;
private readonly string _relFilePath;

public DummyStreamWriter(InMemoryFileManager owner, string relFilePath, Encoding encoding) :
base(new MemoryStream(), encoding)
public DummyStreamWriter(
InMemoryFileManager owner,
string relFilePath,
Encoding encoding
)
: base(new MemoryStream(), encoding)
{
_owner = owner;
_relFilePath = relFilePath;
Expand All @@ -214,7 +259,9 @@ protected override void Dispose(bool disposing)
{
Flush();

_owner._fileSystem[_relFilePath] = new InMemoryFile(((MemoryStream)BaseStream).ToArray());
_owner._fileSystem[_relFilePath] = new InMemoryFile(
((MemoryStream)BaseStream).ToArray()
);

base.Dispose(disposing);
}
Expand All @@ -230,7 +277,8 @@ private sealed class DummyBinaryWriter : BinaryWriter
private readonly InMemoryFileManager _owner;
private readonly string _relFilePath;

public DummyBinaryWriter(InMemoryFileManager owner, string relFilePath) : base(new MemoryStream())
public DummyBinaryWriter(InMemoryFileManager owner, string relFilePath)
: base(new MemoryStream())
{
_owner = owner;
_relFilePath = relFilePath;
Expand All @@ -239,7 +287,9 @@ public DummyBinaryWriter(InMemoryFileManager owner, string relFilePath) : base(n
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_owner._fileSystem[_relFilePath] = new InMemoryFile(((MemoryStream)BaseStream).ToArray());
_owner._fileSystem[_relFilePath] = new InMemoryFile(
((MemoryStream)BaseStream).ToArray()
);
}
}
#endregion
Expand Down
11 changes: 6 additions & 5 deletions c-sharp-tests/PapiTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ internal abstract class PapiTestBase

#region Test setup/teardown
[SetUp]
public virtual async Task TestSetup()
public virtual Task TestSetup()
{
if (OperatingSystem.IsMacOS())
Assert.Ignore("Mac is missing ICU support so these tests will not work");

_projects = new DummyLocalParatextProjects();
_client = new DummyPapiClient();

return Task.CompletedTask;
}

[TearDown]
Expand Down Expand Up @@ -73,12 +75,11 @@ protected DummyLocalParatextProjects ParatextProjects

#region Helper methods to create test data
/// <summary>
/// Creates a new dummy project for testing purposes. The project is added to the ScrTextCollection.
/// Creates a new dummy project for testing purposes
/// </summary>
protected static DummyScrText CreateDummyProject()
{
DummyScrText scrText = new();
ScrTextCollection.Add(scrText, true);
return scrText;
}

Expand All @@ -100,8 +101,8 @@ protected static ProjectDetails CreateProjectDetails(
List<string>? projectInterfaces = null
)
{
ProjectMetadata metadata = new(id, name, projectInterfaces ?? []);
return new ProjectDetails(metadata, "testDirectoryThatDoesNotExist");
ProjectMetadata metadata = new(id, projectInterfaces ?? []);
return new ProjectDetails(name, metadata, "testDirectoryThatDoesNotExist");
}

/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions c-sharp-tests/Projects/FixtureSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ namespace TestParanextDataProvider.Projects
[ExcludeFromCodeCoverage]
public class FixtureSetup
{
private static readonly string s_testFolder = Path.Combine(Path.GetTempPath(), "Platform.Bible.Tests");
private static readonly string s_testFolder = Path.Combine(
Path.GetTempPath(),
"Platform.Bible.Tests"
);

public static string TestFolderPath => s_testFolder;

[OneTimeSetUp]
public void RunBeforeAnyTests()
Expand All @@ -26,7 +31,6 @@ public void RunAfterAnyTests()
// Clean up after the tests are run.
if (Directory.Exists(s_testFolder))
Directory.Delete(s_testFolder, true);

}
}
}
Loading
Loading