def setUp(self): self.test_data = { "id": 1, "first_name": "Zebadiah", "last_name": "Anderton", "email": "*****@*****.**", "gender": "Male", "ip_address": "160.42.195.192" } self.serializers = { "msgpack": msgpack, "pickle": pickle, "yaml": yaml, "json": json } self.file_extensions = { ".pickle": pickle, ".yaml": yaml, ".msgp": msgpack, ".json": json, ".unknown": None } # Clear the temporary directory to store the test files. self.flex_file_temp: Path = (test_path / "flex_file_temp") if self.flex_file_temp.exists(): rrmdir(self.flex_file_temp) self.flex_file_temp.mkdir()
def test_find_project_root_path(self): """ Tests whether the find_batch_root function works as expected. """ project_path: Path = test_temp_projects_path / "root_find" rrmdir(project_path) project_path.mkdir() # The dir still doesn't contain the .cwmp dir. So it should raise an error. with self.assertRaisesRegex( ValueError, r"Not a valid cw.mp project directory \(or any of the parent directories\): Missing \.cwmp directory" ): Project.find_package_root_path(project_path) # We now create the .dcds dir and try to find it. (project_path / ".cwmp").mkdir() root_dir = Project.find_package_root_path(project_path) self.assertTrue(root_dir.samefile(project_path)) # Now from a subdirectory subdir = project_path / "subdir" subdir.mkdir() root_dir = Project.find_package_root_path(subdir) self.assertTrue(root_dir.samefile(project_path))
def test_project_batch_configuration(self): """ Initializes a new directory and check whether the configuration class is found correctly, by checking the instance the Batch class creates. """ project_path = test_temp_projects_path / "config_batch" project = Project.initialize(project_path) batch_instance = project.batch self.assertIsInstance(batch_instance, BatchConfigurationBase) rrmdir(project_path)
def test_project_name(self): """ Initializes a new directory and checks whether the find_source_package_name function works. """ project_path = test_temp_projects_path / "package_name_batch" rrmdir(project_path) Project.initialize(project_path) package_name = Project.find_python_package_name(project_path) self.assertEqual("package_name_batch", package_name)
def test_initialize_new_project_directory(self): """ Initializes a new cw.mp project and checks whether it contains the correct files. """ project_path = test_temp_projects_path / "init_batch" rrmdir(project_path) Project.initialize(project_path) # List of all files and directories whitch should have been created. correct_paths = { 'init_batch', '.cwmp', 'readme.md', 'init_batch/configuration.py', 'init_batch/__init__.py', '.cwmp/cwmp.txt' } # Get list of all files and directories that where created. paths = set() for path in project_path.rglob("*"): paths.add(str(PurePosixPath(path.relative_to(project_path)))) self.assertEqual(paths, correct_paths)