def test_copy_should_raise_if_failure(self, shutil_mock): exception = OSError() shutil_mock.copytree.side_effect = exception with self.assertRaises(OSError) as context: io.copy("source/path/", "dest/path/") self.assertEqual(exception, context.exception) shutil_mock.copy.assert_not_called()
def test_copy_single_file(self, shutil_mock): shutil_mock.copytree.side_effect = OSError(errno.ENOTDIR, "some reason") io.copy("source/path/file.yaml", "dest/path/file.yaml") shutil_mock.copytree.assert_called_once() shutil_mock.copy.assert_called_with("source/path/file.yaml", "dest/path/file.yaml")
def test_copy_should_raise_if_failure(): with pytest.raises(Exception): fixtures_directory_path = Path(os.path.dirname(__file__), "..", "__abcdefg").resolve() destination_path = Path(os.path.dirname(__file__), "..", "__abcdefg_copy").resolve() io.copy(fixtures_directory_path, destination_path)
def test_copy_single_file(): fixtures_directory_path = Path(os.path.dirname(__file__), "..", "__fixtures__", "example.yaml").resolve() destination_path = Path(os.path.dirname(__file__), "..", "__fixtures__", "example_copy.yaml").resolve() io.copy(fixtures_directory_path, destination_path) assert os.path.isfile(destination_path) os.remove(destination_path)
def test_copy_directory_with_content(): fixtures_directory_path = Path(os.path.dirname(__file__), "..", "__fixtures__").resolve() destination_path = Path(os.path.dirname(__file__), "..", "__fixtures__copy").resolve() fixtures_files = os.listdir(fixtures_directory_path) io.copy(fixtures_directory_path, destination_path) copied_fixtures_files = os.listdir(destination_path) assert os.path.isdir(destination_path) assert fixtures_files == copied_fixtures_files shutil.rmtree(destination_path)
def test_copy_directory_with_content(self, shutil_mock): io.copy("source/path/", "dest/path/") shutil_mock.copytree.assert_called_once() shutil_mock.copy.assert_not_called()