Skip to content

Commit

Permalink
Merge pull request #73 from SynBioDex/fix-line_endings
Browse files Browse the repository at this point in the history
Change test to perform string comparison rather than file comparison
  • Loading branch information
bbartley authored May 17, 2022
2 parents 8964be6 + 36fd442 commit 4b9b3a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(name='sbol_factory',
description='Ontology-driven data modeling',
version='1.0a12',
version='1.0a13',
install_requires=[
'sbol3>=1.0b12', # Note: implicitly includes rdflib
'sparqlwrapper>=1.8.5',
Expand Down
31 changes: 9 additions & 22 deletions test/test_ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,14 @@ def test_build_with_ontology(self):
v = doc.validate()
assert not v.errors and not v.warnings, "".join(str(e) for e in doc.validate().errors)

temp_name = os.path.join(tempfile.gettempdir(), 'mini_library.nt')
doc.write(temp_name, sbol3.SORTED_NTRIPLES)
actual = doc.write_string(file_format=sbol3.SORTED_NTRIPLES)

#Use \n as a newline instead of \r\n for windows compatibility
with open(temp_name) as f:
file_str = f.read()
with open(temp_name, "w", newline='\n') as f:
f.write(file_str)

print(f'Wrote file as {temp_name}')

comparison_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_files', 'mini_library.nt')
print(f'Comparing against {comparison_file}')
assert filecmp.cmp(temp_name, comparison_file), "Files are not identical"
doc = sbol3.Document()
doc.read(comparison_file)
expected = doc.write_string(file_format=sbol3.SORTED_NTRIPLES)
assert expected == actual
print('File identical with test file')

def test_round_trip_with_ontology(self):
Expand All @@ -98,19 +92,12 @@ def test_round_trip_with_ontology(self):
v = doc.validate()
assert not v.errors and not v.warnings, "".join(str(e) for e in doc.validate().errors)

temp_name = os.path.join(tempfile.gettempdir(), 'mini_library.nt')
doc.write(temp_name, sbol3.SORTED_NTRIPLES)

#Use \n as a newline instead of \r\n for windows compatibility
with open(temp_name) as f:
file_str = f.read()
with open(temp_name, "w", newline='\n') as f:
f.write(file_str)

print(f'Wrote file as {temp_name}')
with open(original_file, 'r') as f:
expected = f.read()
actual = doc.write_string(file_format=sbol3.SORTED_NTRIPLES)

print(f'Comparing against {original_file}')
assert filecmp.cmp(temp_name, original_file), "Files are not identical"
assert actual == expected, "Files are not identical"
print('Written out file identical with original file')


Expand Down

0 comments on commit 4b9b3a6

Please sign in to comment.