diff --git a/test/test_sbol2_sbol3_direct.py b/test/test_sbol2_sbol3_direct.py index 51caaa03..a42fa61f 100644 --- a/test/test_sbol2_sbol3_direct.py +++ b/test/test_sbol2_sbol3_direct.py @@ -24,14 +24,15 @@ def test_3to2_conversion(self): doc2 = convert3to2(doc3, True) #report = doc2.validate() #self.assertEqual(len(report), 0, f'Validation failed: {report}') - with tempfile.NamedTemporaryFile(suffix='.xml') as tmp2: - doc2.write(tmp2.name) - self.assertFalse(file_diff(tmp2.name, str(TEST_FILES / 'BBa_J23101.xml'))) + with tempfile.TemporaryDirectory() as tmpdir: + tmp2 = Path(tmpdir) / 'doc2.xml' + doc2.write(tmp2) + self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'BBa_J23101.xml'))) doc3_loop = convert2to3(doc2, use_native_converter=True) self.assertEqual(len(doc3_loop.validate()), 0) - with tempfile.NamedTemporaryFile(suffix='.nt') as tmp3: - doc3_loop.write(tmp3.name) - self.assertFalse(file_diff(tmp3.name, str(TEST_FILES / 'BBa_J23101_patched.nt'))) + tmp3 = Path(tmpdir) / 'doc3_loop.nt' + doc3_loop.write(tmp3) + self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'BBa_J23101_patched.nt'))) def test_2to3_conversion(self): """Test ability to convert a simple part from SBOL3 to SBOL2""" @@ -41,15 +42,16 @@ def test_2to3_conversion(self): # Convert to SBOL3 and check contents doc3 = convert2to3(doc2, use_native_converter=True) self.assertEqual(len(doc3.validate()), 0) - with tempfile.NamedTemporaryFile(suffix='.nt') as tmp3: - doc3.write(tmp3.name) - self.assertFalse(file_diff(tmp3.name, str(TEST_FILES / 'BBa_J23101_patched.nt'))) + with tempfile.TemporaryDirectory() as tmpdir: + tmp3 = Path(tmpdir) / 'doc3.nt' + doc3.write(tmp3) + self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'BBa_J23101_patched.nt'))) doc2_loop = convert3to2(doc3, True) # report = doc2.validate() # self.assertEqual(len(report), 0, f'Validation failed: {report}') - with tempfile.NamedTemporaryFile(suffix='.xml') as tmp2: - doc2_loop.write(tmp2.name) - self.assertFalse(file_diff(tmp2.name, str(TEST_FILES / 'BBa_J23101.xml'))) + tmp2 = Path(tmpdir) / 'doc2_loop.xml' + doc2_loop.write(tmp2) + self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'BBa_J23101.xml'))) if __name__ == '__main__':