diff --git a/TODO.md b/TODO.md index 1d47a70..23decbc 100644 --- a/TODO.md +++ b/TODO.md @@ -3,7 +3,7 @@ ## Tests - [ ] Commandline -- [ ] File +- [x] File - [ ] DynamoFile - [ ] PythonFile - [x] PythonNode diff --git a/tests/support.py b/tests/support.py index f8c6224..df7b054 100644 --- a/tests/support.py +++ b/tests/support.py @@ -1,4 +1,5 @@ import pathlib +import dyn2py INPUT_DIR = "tests/input_files" OUTPUT_DIR = "tests/output_files" @@ -10,3 +11,15 @@ def cleanup_output_dir(): f.unlink() else: output_dir.mkdir() + + +def extract_single_node_dyn(): + """Extract python from single_node.dyn + File will be here: f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py" + """ + cleanup_output_dir() + + # Extract py: + options = dyn2py.Options(python_folder=OUTPUT_DIR) + dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/single_node.dyn") + dyn.extract_python(options) diff --git a/tests/test_File.py b/tests/test_File.py index 3d0f9d3..5750fce 100644 --- a/tests/test_File.py +++ b/tests/test_File.py @@ -8,10 +8,6 @@ from tests.support import * class TestFile(unittest.TestCase): - # Methods to test: - # is_dynamo_file - # is_python_file - def test_init(self): paths = [ f"{INPUT_DIR}/python_nodes.dyn", @@ -65,8 +61,12 @@ class TestFile(unittest.TestCase): 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) + older_file = dyn2py.File(f"{INPUT_DIR}/python_nodes.dyn") - newer_file = dyn2py.File(f"{INPUT_DIR}/no_python.dyn") nonexisting_file = dyn2py.File(f"{INPUT_DIR}/new_file.dyn") self.assertTrue(newer_file.is_newer(older_file)) @@ -88,3 +88,21 @@ class TestFile(unittest.TestCase): with self.assertRaises(TypeError): nonexisting_file.write(options) + + def test_is_file(self): + + extract_single_node_dyn() + + paths = [ + (f"{INPUT_DIR}/python_nodes.dyn", "dyn"), + (f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py", "py"), + (f"README.md", ""), + ] + + 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") + + diff --git a/tests/test_PythonNode.py b/tests/test_PythonNode.py index 13bf889..e910547 100644 --- a/tests/test_PythonNode.py +++ b/tests/test_PythonNode.py @@ -32,12 +32,7 @@ class TestPythonNode(unittest.TestCase): def test_init_from_py(self): - cleanup_output_dir() - - # Extract py: - options = dyn2py.Options(python_folder=OUTPUT_DIR) - dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/single_node.dyn") - dyn.extract_python(options) + extract_single_node_dyn() # Open the extracted file and replace a string: with open(f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py") as orig_py, \