def test_on_uncreatable_file(self): with tempfile.TemporaryDirectory() as parent_directory: # Create a file name with a char forbidden in POSIX and WIN* forbidden_char = "/" file_name = "SOMEDIR{}".format(forbidden_char) file_path = os.path.join(parent_directory, file_name) # Assert that the forbidden character prohibited path creation self.assertFalse(is_existing_or_creatable_path(file_path))
def test_on_nonexisting_creatable_file(self): # Create and delete a temp file so we know that it is a valid path file1 = tempfile.mkstemp()[1] os.remove(file1) self.assertTrue(is_existing_or_creatable_path(file1))
def test_on_nonexisting_creatable_dir(self): # Create and delete a temp directory so we know that it is a valid path dir1 = tempfile.mkdtemp() os.rmdir(dir1) self.assertTrue(is_existing_or_creatable_path(dir1))
def test_on_existing_file(self): with tempfile.NamedTemporaryFile() as file1: self.assertTrue(is_existing_or_creatable_path(file1.name))
def test_on_existing_dir(self): with tempfile.TemporaryDirectory() as dir1: self.assertTrue(is_existing_or_creatable_path(dir1))