def setUp(self): """ Application configuration file will be read and components will be loaded. """ self.file_to_read = "cartola_sandbox.txt" self.file_to_read_path = tests.get_sandbox_path(self.file_to_read) self.file_to_write = "cartola_file_write_test.txt" self.file_to_write_path = tests.get_sandbox_path(self.file_to_write) fs.remove_existing(self.file_to_write_path)
def test_fs_touch(self): """ Create(touch) a new file. """ file_target = tests.get_sandbox_path("file_to_touch.txt") self.assertFalse(os.path.exists(file_target)) fs.touch(file_target) self.assertTrue(os.path.exists(file_target)) fs.remove_existing(file_target)
def test_fs_only_files_from(self): """ Test only_files_from function from fs """ dir_target = tests.get_sandbox_path("parent_dir") for child_file in fs.only_files_from(dir_target, False): self.assertTrue(os.path.isfile(os.path.join(dir_target, child_file))) for child_file in fs.only_files_from(dir_target): self.assertTrue(os.path.isfile(child_file))
def test_fs_rmdir_existing(self): """ Remove a directory is it exists.""" dir_target = tests.get_sandbox_path("rmdir_existing_dir") self.assertFalse(fs.rmdir_existing(dir_target)) os.mkdir(dir_target) self.assertTrue(os.path.exists(dir_target)) self.assertTrue(fs.rmdir_existing(dir_target)) self.assertFalse(os.path.exists(dir_target))
def test_fs_remove_existing(self): """ Remove a file is it exists. """ file_target = tests.get_sandbox_path("remove_existing_file.txt") self.assertFalse(fs.remove_existing(file_target)) fs.touch(file_target) self.assertTrue(os.path.exists(file_target)) self.assertTrue(fs.remove_existing(file_target)) self.assertFalse(os.path.exists(file_target))
def test_fs_create_module(self): """ Create a module structure in a target directory. """ fs.create_module("monster.of.the.lake", tests.SANDBOX_PATH) self.assertTrue(os.path.exists(tests.get_sandbox_path( os.path.join("monster", "of", "the", "lake") ))) self.assertTrue(os.path.exists(tests.get_sandbox_path( os.path.join("monster", "__init__.py") ))) self.assertTrue(os.path.exists(tests.get_sandbox_path( os.path.join("monster", "of", "__init__.py") ))) self.assertTrue(os.path.exists(tests.get_sandbox_path( os.path.join("monster", "of", "the", "__init__.py") ))) self.assertTrue(os.path.exists(tests.get_sandbox_path( os.path.join("monster", "of", "the", "lake", "__init__.py") )))
def test_fs_only_dirs_from(self): """ Test only_dirs_from function from fs """ dir_target = tests.get_sandbox_path("parent_dir") for child_dir in fs.only_dirs_from(dir_target, False): self.assertTrue(os.path.isdir(os.path.join(dir_target, child_dir))) for child_dir in fs.only_dirs_from(dir_target): self.assertTrue(os.path.isdir(child_dir)) result = fs.only_dirs_from( os.path.join(dir_target, "child_file_1.txt")) self.assertTrue(result is None)
def tearDown(self): fs.remove_existing(tests.get_sandbox_path( os.path.join("monster", "__init__.py"))) fs.remove_existing(tests.get_sandbox_path( os.path.join("monster", "of", "__init__.py"))) fs.remove_existing(tests.get_sandbox_path( os.path.join("monster", "of", "the", "__init__.py"))) fs.remove_existing(tests.get_sandbox_path( os.path.join("monster", "of", "the", "lake", "__init__.py"))) fs.rmdir_existing(tests.get_sandbox_path( os.path.join("monster", "of", "the", "lake"))) fs.rmdir_existing(tests.get_sandbox_path( os.path.join("monster", "of", "the"))) fs.rmdir_existing(tests.get_sandbox_path( os.path.join("monster", "of"))) fs.rmdir_existing(tests.get_sandbox_path( os.path.join("monster")))