Move read() methods to __init__(), new tests

This commit is contained in:
2023-03-13 19:04:24 +01:00
parent 4acc0e5da2
commit c40ff88bcf
8 changed files with 248 additions and 217 deletions

View File

@@ -8,6 +8,8 @@ from tests.support import *
class TestFile(unittest.TestCase):
# Write methods should be tested in subclasses!
def test_init(self):
paths = [
f"{INPUT_DIR}/python_nodes.dyn",
@@ -33,23 +35,25 @@ class TestFile(unittest.TestCase):
self.assertEqual(the_file.extension, ".dyn")
self.assertFalse(the_file.modified)
self.assertEqual(the_file.__class__, dyn2py.DynamoFile)
def test_init_newfile(self):
paths = [
f"{INPUT_DIR}/new_file.dyn",
pathlib.Path(f"{INPUT_DIR}/new_file.dyn")
f"{INPUT_DIR}/new_file.py",
pathlib.Path(f"{INPUT_DIR}/new_file.py")
]
if platform.system() == "Windows":
paths.extend([
fr"{INPUT_DIR}\new_file.dyn",
pathlib.Path(fr"{INPUT_DIR}\new_file.dyn")
fr"{INPUT_DIR}\new_file.py",
pathlib.Path(fr"{INPUT_DIR}\new_file.py")
])
for path in paths:
the_file = dyn2py.File(path)
self.assertEqual(the_file.filepath,
pathlib.Path(f"{INPUT_DIR}/new_file.dyn"))
pathlib.Path(f"{INPUT_DIR}/new_file.py"))
self.assertEqual(the_file.basename, "new_file")
self.assertEqual(the_file.dirpath, pathlib.Path(INPUT_DIR))
self.assertEqual(the_file.realpath, pathlib.Path(path).resolve())
@@ -57,17 +61,21 @@ class TestFile(unittest.TestCase):
self.assertEqual(the_file.mtime, 0.0)
self.assertEqual(the_file.mtimeiso, "")
self.assertFalse(the_file.exists)
self.assertEqual(the_file.extension, ".dyn")
self.assertEqual(the_file.extension, ".py")
self.assertFalse(the_file.modified)
def test_newer(self):
# Touch a file, so it will be always newer than the others:
touched_file = pathlib.Path(f"{OUTPUT_DIR}/touched_file.py")
touched_file.touch()
newer_file = dyn2py.File(touched_file)
self.assertEqual(the_file.__class__, dyn2py.PythonFile)
older_file = dyn2py.File(f"{INPUT_DIR}/python_nodes.dyn")
nonexisting_file = dyn2py.File(f"{INPUT_DIR}/new_file.dyn")
def test_newer(self):
older_file = dyn2py.File(f"{INPUT_DIR}/single_node.dyn")
nonexisting_file = dyn2py.File(f"{INPUT_DIR}/new_file.py")
# Extract a python file so it is always newer than the others:
cleanup_output_dir()
opt = dyn2py.Options(python_folder=OUTPUT_DIR)
older_file.extract_python(options=opt) # type: ignore
newer_file = dyn2py.File(
f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py")
self.assertTrue(newer_file.is_newer(older_file))
self.assertTrue(newer_file.is_newer(nonexisting_file))
@@ -78,17 +86,6 @@ class TestFile(unittest.TestCase):
self.assertFalse(nonexisting_file.is_newer(older_file))
self.assertFalse(nonexisting_file.is_newer(newer_file))
def test_write(self):
existing_file = dyn2py.File(f"{INPUT_DIR}/python_nodes.dyn")
nonexisting_file = dyn2py.File(f"{INPUT_DIR}/new_file.dyn")
options = dyn2py.Options()
with self.assertRaises(TypeError):
existing_file.write(options)
with self.assertRaises(TypeError):
nonexisting_file.write(options)
def test_is_file(self):
extract_single_node_dyn()
@@ -101,8 +98,6 @@ class TestFile(unittest.TestCase):
for path, f in paths:
file = dyn2py.File(path)
self.assertEqual(file.is_dynamo_file(), f=="dyn")
self.assertEqual(file.is_python_file(), f=="py")
self.assertEqual(file.is_dynamo_file(), f == "dyn")
self.assertEqual(file.is_python_file(), f == "py")