Skip to content

Commit

Permalink
Got tests passing now
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyman192 committed Jan 9, 2025
1 parent de7ad5c commit 9ad065d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
15 changes: 7 additions & 8 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def pytest_sessionstart(session):
@pytest.fixture(scope='session')
def convert_files():
# First, figure out the first part of the MBINCompiler call.
print("HI")
platform = os.environ.get('platform')
mbincompiler_path = os.environ.get('mbincompiler_path')
if mbincompiler_path is not None:
Expand All @@ -99,19 +98,19 @@ def convert_files():

datapath = os.environ.get('datapath', DATA_PATH)

# Next, convert all the mbin files in the data folder to a `data_exml`
# Next, convert all the mbin files in the data folder to a `data_mxml`
# folder.
# We'll have a double nested with statement so we can have both temp
# directories existing for the whole lifecycle of the tests.
with tempfile.TemporaryDirectory(prefix='exml_') as temp_exml_dir:
with tempfile.TemporaryDirectory(prefix='mxml_') as temp_mxml_dir:
with tempfile.TemporaryDirectory(prefix='mbin_') as temp_mbin_dir:
print('Converting the original files to .EXML')
subprocess.run(cmd + [datapath, '-iMBIN', f'--output-dir={temp_exml_dir}'])
print('Converting the converted .EXML files back to .MBIN')
print('Converting the original files to .MXML')
subprocess.run(cmd + [datapath, '-iMBIN', f'--output-dir={temp_mxml_dir}'])
print('Converting the converted .MXML files back to .MBIN')
subprocess.run(
cmd + [temp_exml_dir, '-iEXML', f'--output-dir={temp_mbin_dir}']
cmd + [temp_mxml_dir, '-iMXML', f'--output-dir={temp_mbin_dir}']
)
yield temp_exml_dir, temp_mbin_dir
yield temp_mxml_dir, temp_mbin_dir


@pytest.hookimpl(tryfirst=True, hookwrapper=True)
Expand Down
20 changes: 13 additions & 7 deletions libMBIN/Source/Template/NMSTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,6 @@ public EXmlBase SerializeEXmlValue(Type fieldType, FieldInfo field, NMSAttribute
int i = 0;
string valueString = String.Empty;


switch (fieldType.Name)
{
case "String":
Expand Down Expand Up @@ -1200,7 +1199,7 @@ public EXmlBase SerializeEXmlValue(Type fieldType, FieldInfo field, NMSAttribute
if ( typeof(INMSString).IsAssignableFrom(listType) ) {
// For lists of strings, just write the data directly.
foreach ( var template in templates ) {
EXmlBase data = new EXmlProperty {
EXmlProperty data = new EXmlProperty {
Name = field.Name,
Value = ((INMSString)template).StringValue(),
};
Expand Down Expand Up @@ -1468,16 +1467,23 @@ public static object DeserializeEXmlValue(NMSTemplate template, Type fieldType,

var type = innerXmlData.GetType();
var data = innerXmlData as EXmlProperty;
if (typeof(INMSString).IsAssignableFrom(elementType) && elementType.Name == "NMSString0x20A") {
// If the data is actually a NMSString0x20A, then make sure we try and serialize it as such.
data.Value = "NMSString0x20A.xml";
bool isGenericTemplate = false;

if (typeof(INMSString).IsAssignableFrom(elementType)) {
// If the data is a string, we read as a property since it won't have the type.
type = typeof(EXmlProperty);
} else if (elementType == typeof(NMSTemplate)) {
isGenericTemplate = true;
type = typeof(EXmlData);
} else {
type = (data?.Value.EndsWith( ".xml" ) ?? false) ? typeof( EXmlData ) : type;
}
type = (data?.Value.EndsWith( ".xml" ) ?? false) ? typeof( EXmlData ) : type;

if (type == typeof(EXmlProperty)) {
element = DeserializeEXmlValue(template, elementType, field, (EXmlProperty)innerXmlData, templateType, settings);
} else if (type == typeof(EXmlData)) {
element = DeserializeEXml(innerXmlData); // child template if <Data> tag or <Property> tag with value ending in .xml (todo: better way of finding <Property> child templates)
// child template if <Data> tag or <Property> tag with value ending in .xml (todo: better way of finding <Property> child templates)
element = DeserializeEXml(innerXmlData, isGenericTemplate);
} else if (type == typeof(EXmlMeta)) {
DebugLogComment(((EXmlMeta)innerXmlData).Comment);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/bytecompare_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def test_compare(convert_files, fname):
This test is parameterised by fpath which will contain the paths of all
.MBIN files in the ./data directory.
"""
converted_exml_dir, converted_mbin_dir = convert_files
converted_exml = op.join(converted_exml_dir, fname + '.MXML')
converted_mxml_dir, converted_mbin_dir = convert_files
converted_mxml = op.join(converted_mxml_dir, fname + '.MXML')
converted_mbin = op.join(converted_mbin_dir, fname + '.MBIN')
if not op.exists(converted_exml):
if not op.exists(converted_mxml):
# If the .MXML file doesn't exist, fail.
print(f'{fname},{TO_MXML_FAIL}')
pytest.fail()
Expand Down

0 comments on commit 9ad065d

Please sign in to comment.