Beispiel #1
0
    def test_nonexistant_dir_raises_error(self):
        with tempfile.TemporaryDirectory() as tmp_dir:
            # Arrange.
            input_list = [f'{tmp_dir}/nonexistant-dir/ > /']
            out_filename = f'{tmp_dir}/out.zip'

            # Act & Assert.
            with self.assertRaises(ZipError):
                zip_up(input_list, out_filename)
Beispiel #2
0
    def test_zip_up_file(self):
        with tempfile.TemporaryDirectory() as tmp_dir:
            # Arrange.
            tmp_path = pathlib.Path(tmp_dir)
            in_path = make_directory(tmp_path, 'in', IN_FILENAMES)
            input_list = [f'{in_path}/file1.txt {DELIMITER} /']
            out_filename = f'{tmp_path}/out.zip'

            # Act.
            zip_up(input_list, out_filename)
            out_path = pathlib.Path(f'{tmp_path}/out/')
            with zipfile.ZipFile(out_filename, 'r') as zip_file:
                zip_file.extractall(out_path)
            expected_path = make_directory(tmp_path, 'expected', ['file1.txt'])

            # Assert.
            self.assertSetEqual(get_directory_contents(out_path),
                                get_directory_contents(expected_path))
Beispiel #3
0
    def test_wrong_input_syntax_raises_error(self):
        with tempfile.TemporaryDirectory() as tmp_dir:
            # Arrange.
            bad_inputs = [
                '',  # Empty input
                f'{tmp_dir}/ /',  # No delimiter
                f'{tmp_dir}/ {DELIMITER} ',  # No zip destination
                f'{tmp_dir} /',  # No source
                f'{tmp_dir}/',  # No delimiter or zip destination
                f'{DELIMITER}',  # No source or zip destination
                f'{tmp_dir} {DELIMITER} /',  # No trailing source '/'
                f'{tmp_dir}/ {DELIMITER} foo/',  # No leading zip root '/'
                f'{tmp_dir}/ {DELIMITER} /foo',  # No trailing zip dest '/'
                f'{tmp_dir}/ {DELIMITER} /{tmp_dir}/ '
                f'{DELIMITER} /{tmp_dir}/',  # Too many paths on split
            ]
            out_filename = f'{tmp_dir}/out.zip'

            # Act & Assert.
            for bad_input in bad_inputs:
                with self.assertRaises(ZipError):
                    zip_up([bad_input], out_filename)