Exemplo n.º 1
0
    def test_subclass_not_implement_get_delta_cmd(self):
        tmp_delta = deltas.BaseDeltasGenerator(
            source_path=self.source_file,
            target_path=self.target_file,
            delta_format="xdelta3",
            delta_tool=self.delta_tool_path,
        )

        self.assertThat(
            lambda: tmp_delta.make_delta(is_for_test=True),
            m.raises(NotImplementedError),
        )
Exemplo n.º 2
0
    def test_file_existence_failed(self):
        class Tmpdelta(deltas.BaseDeltasGenerator):
            pass

        self.assertThat(
            lambda: deltas.BaseDeltasGenerator(
                source_path="invalid-source-file",
                target_path=self.target_file,
                delta_format="xdelta3",
                delta_tool="delta-gen-tool-path",
            ),
            m.raises(ValueError),
        )
        self.assertThat(
            lambda: deltas.BaseDeltasGenerator(
                source_path=self.source_file,
                target_path="invalid-target_file",
                delta_format="xdelta3",
                delta_tool="delta-gen-tool-path",
            ),
            m.raises(ValueError),
        )
Exemplo n.º 3
0
    def test_find_unique_file_name(self):
        tmp_delta = deltas.BaseDeltasGenerator(
            source_path=self.source_file,
            target_path=self.target_file,
            delta_format="xdelta3",
            delta_tool=self.delta_tool_path,
        )

        unique_file_name = tmp_delta.find_unique_file_name(
            tmp_delta.source_path)
        self.assertThat(unique_file_name,
                        m.Equals(tmp_delta.source_path + "-0"))
        with open(unique_file_name, "wb") as f:
            f.write(b"tmp file.")

        self.assertThat(
            tmp_delta.find_unique_file_name(tmp_delta.source_path),
            m.Equals(tmp_delta.source_path + "-1"),
        )
Exemplo n.º 4
0
    def test_not_set_delta_property_correctly(self):
        self.assertThat(
            lambda: deltas.BaseDeltasGenerator(
                source_path=self.source_file,
                target_path=self.target_file,
                delta_format="not-defined",
                delta_tool="/usr/bin/xdelta3",
            ),
            m.raises(deltas.errors.DeltaFormatOptionError),
        )
        exception = self.assertRaises(
            deltas.errors.DeltaFormatOptionError,
            deltas.BaseDeltasGenerator,
            source_path=self.source_file,
            target_path=self.target_file,
            delta_format="invalid-delta-format",
            delta_tool=self.delta_tool_path,
        )
        expected = """delta_format must be a option in ['xdelta3'].
for now delta_format='invalid-delta-format'"""
        self.assertThat(str(exception), m.Equals(expected))
Exemplo n.º 5
0
    def test_large_delta_raises_error(self):
        delta_file = os.path.join(self.workdir, "target.snap.delta")
        target_file = os.path.join(self.workdir, "target.snap")
        source_file = os.path.join(self.workdir, "source.snap")

        with open(delta_file, "wb") as delta, open(source_file,
                                                   "wb") as source:
            delta.seek(999 - 1)
            delta.write(b"\0")
            source.seek(1000 - 1)
            source.write(b"\0")

        generator = deltas.BaseDeltasGenerator(
            source_path=source_file,
            target_path=target_file,
            delta_format="xdelta3",
            delta_tool=self.delta_tool_path,
        )

        self.assertThat(
            lambda: generator._check_delta_size_constraint(delta_file),
            m.raises(deltas.errors.DeltaGenerationTooBigError),
        )