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 4 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
4 changes: 3 additions & 1 deletion c-sharp-tests/DummyLocalParatextProjects.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using Paranext.DataProvider.Projects;
using Paratext.Data;

namespace TestParanextDataProvider
{
Expand All @@ -8,7 +9,8 @@ internal class DummyLocalParatextProjects : LocalParatextProjects
{
public void FakeAddProject(ProjectDetails details)
{
_projectDetailsMap[details.Metadata.ID] = details;
var dummyScrText = new DummyScrText(details);
ScrTextCollection.Add(dummyScrText, 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
8 changes: 5 additions & 3 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 @@ -100,8 +102,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
24 changes: 12 additions & 12 deletions c-sharp-tests/Projects/LocalParatextProjectsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public void TearDown()
[TestCase("ABC")]
public void Initialize_NonStandardFolderName_ProjectIsRetrievable(string folder)
{
CreateTempProject(folder, CreateParatextProjectMetadata("ABC"));
CreateTempProject(folder, CreateParatextProjectDetails(folder, "ABC"));

_localProjects.Initialize(false);
var details = _localProjects.GetAllProjectDetails().Single();
Assert.That(details, Is.EqualTo(_localProjects.GetProjectDetails(TEST_ID)));
Assert.That(details.HomeDirectory, Does.EndWith(folder));
Assert.That(details.Metadata.Name, Is.EqualTo("ABC"));
Assert.That(details.Name, Is.EqualTo("ABC"));
Assert.That(details.Metadata.ID.Equals(TEST_ID, StringComparison.OrdinalIgnoreCase));
}

Expand All @@ -55,27 +55,27 @@ public void Initialize_NonStandardFolderName_ProjectIsRetrievable(string folder)
[TestCase("A-B-C_441f1e41ffb8d319650847df35f4ffb78f12914e", "ABC")]
public void Initialize_NameDoesNotMatch_ProjectIsRetrievable(string folder, string name)
{
var metadata = CreateParatextProjectMetadata(name);
var metadata = CreateParatextProjectDetails(folder, name);
CreateTempProject(folder, metadata);
_localProjects.Initialize(false);
var details = _localProjects.GetAllProjectDetails().Single();
Assert.That(details, Is.EqualTo(_localProjects.GetProjectDetails(TEST_ID)));
Assert.That(details.HomeDirectory, Does.EndWith(folder));
Assert.That(details.Metadata.Name, Is.EqualTo(name));
Assert.That(details.Name, Is.EqualTo(name));
Assert.That(details.Metadata.ID.Equals(TEST_ID, StringComparison.OrdinalIgnoreCase));
}

[TestCase("ABC_541f1e41ffb8d319650847df35f4ffb78f12914e", "ABC")]
[TestCase("AB-C_541f1e41ffb8d319650847df35f4ffb78f12914e", "AB-C")]
public void Initialize_IdDoesNotMatch_ProjectIsRetrievable(string folder, string name)
{
var metadata = CreateParatextProjectMetadata(name);
var metadata = CreateParatextProjectDetails(folder, name);
CreateTempProject(folder, metadata);
_localProjects.Initialize(false);
var details = _localProjects.GetAllProjectDetails().Single();
Assert.That(details, Is.EqualTo(_localProjects.GetProjectDetails(TEST_ID)));
Assert.That(details.HomeDirectory, Does.EndWith(folder));
Assert.That(details.Metadata.Name, Is.EqualTo(name));
Assert.That(details.Name, Is.EqualTo(name));
Assert.That(details.Metadata.ID.Equals(TEST_ID, StringComparison.OrdinalIgnoreCase));
}

Expand All @@ -85,25 +85,25 @@ public void Initialize_IdDoesNotMatch_ProjectIsRetrievable(string folder, string
[TestCase("A-B-C_441f1e41ffb8d319650847df35f4ffb78f12914e", "A-B-C")]
public void Initialize_IdAndNameMatch_ProjectIsRetrievable(string folder, string name)
{
var metadata = CreateParatextProjectMetadata(name);
var metadata = CreateParatextProjectDetails(folder, name);
CreateTempProject(folder, metadata);
_localProjects.Initialize(false);
var details = _localProjects.GetAllProjectDetails().Single();
Assert.That(details, Is.EqualTo(_localProjects.GetProjectDetails(TEST_ID)));
Assert.That(details.HomeDirectory, Does.EndWith(folder));
Assert.That(details.Metadata.Name, Is.EqualTo(name));
Assert.That(details.Name, Is.EqualTo(name));
Assert.That(details.Metadata.ID.Equals(TEST_ID, StringComparison.OrdinalIgnoreCase));
}

#endregion

private void CreateTempProject(string folder, ProjectMetadata metadata)
private void CreateTempProject(string folder, ProjectDetails details)
{
((TestLocalParatextProjectsInTempDir)_localProjects).CreateTempProject(folder, metadata);
((TestLocalParatextProjectsInTempDir)_localProjects).CreateTempProject(folder, details);
}

private static ProjectMetadata CreateParatextProjectMetadata(string name)
private static ProjectDetails CreateParatextProjectDetails(string folder, string name)
{
return new ProjectMetadata(TEST_ID, name, ["paratext"]);
return new ProjectDetails(name, new ProjectMetadata(TEST_ID, ["paratext"]), folder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace TestParanextDataProvider.Projects
internal class ParatextProjectDataProviderFactoryTests : PapiTestBase
{
private const string PDB_FACTORY_GET_REQUEST =
$"object:platform.pdpFactory-{ParatextProjectDataProviderFactory.PDPF_NAME}.function";
$"object:platform.pdpFactory-{ParatextProjectDataProviderFactory.PDPF_NAME}-pdpf.function";

[SetUp]
public override async Task TestSetup()
Expand Down Expand Up @@ -110,7 +110,7 @@ public async Task InvalidFunction_ReturnsError()
[Test]
public async Task GetProjectDataProviderID_ReturnsIdForProvider()
{
const string projId = "monkey";
const string projId = "305531";
const int requesterId1 = 47281;
const int requesterId2 = 18542;

Expand Down
6 changes: 3 additions & 3 deletions c-sharp-tests/Projects/TestLocalParatextProjectsInTempDir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public void Dispose()

protected override string ProjectRootFolder => _folder.Path;

internal void CreateTempProject(string folder, ProjectMetadata projectMetadata)
internal void CreateTempProject(string folder, ProjectDetails projectDetails)
{
var folderPath = Path.Combine(ProjectRootFolder, folder);
CreateDirectory(folderPath);
var settings = new MinimalParatextProjectSettings
{
Name = projectMetadata.Name,
Guid = projectMetadata.ID
Name = projectDetails.Name,
Guid = projectDetails.Metadata.ID
};
var settingsPath = Path.Join(folderPath, "Settings.xml");
XmlSerializationHelper.SerializeToFileWithWriteThrough(settingsPath, settings);
Expand Down
Loading
Loading