Exemple #1
0
    def test_save(self):
        global_state = GlobalState()
        global_state.append_build_packages(self.build_packages)
        global_state.append_build_snaps(self.build_snaps)

        global_state.save(filepath="state")

        prepend = "  - "

        if self.build_packages:
            build_packages = "\n" + "\n".join(
                ["{}{}".format(prepend, p) for p in self.build_packages])
        else:
            build_packages = " []"

        if self.build_snaps:
            build_snaps = "\n" + "\n".join(
                ["{}{}".format(prepend, p) for p in self.build_snaps])
        else:
            build_snaps = " []"

        self.assertThat(
            "state",
            FileContains(
                dedent("""\
                    !GlobalState
                    assets:
                      build-packages:{}
                      build-snaps:{}
                    """).format(build_packages, build_snaps)),
        )
Exemple #2
0
    def test_append_duplicate(self):
        global_state = GlobalState()
        global_state.append_build_packages(self.build_packages)
        global_state.append_build_snaps(self.build_snaps)

        self.assertThat(global_state.get_build_packages(), Equals(self.build_packages))
        self.assertThat(global_state.get_build_snaps(), Equals(self.build_snaps))

        global_state.append_build_packages(self.build_packages)
        global_state.append_build_snaps(self.build_snaps)

        self.assertThat(global_state.get_build_packages(), Equals(self.build_packages))
        self.assertThat(global_state.get_build_snaps(), Equals(self.build_snaps))
Exemple #3
0
    def test_append_duplicate(self, tmp_work_path, build_packages, build_snaps,
                              required_grade):
        global_state = GlobalState()
        global_state.append_build_packages(build_packages)
        global_state.append_build_snaps(build_snaps)

        assert global_state.get_build_packages() == build_packages
        assert global_state.get_build_snaps() == build_snaps

        global_state.append_build_packages(build_packages)
        global_state.append_build_snaps(build_snaps)

        assert global_state.get_build_packages() == build_packages
        assert global_state.get_build_snaps() == build_snaps
Exemple #4
0
    def test_save_load_and_append(self, tmp_work_path, build_packages,
                                  build_snaps, required_grade):
        global_state = GlobalState()
        global_state.append_build_packages(build_packages)
        global_state.append_build_snaps(build_snaps)
        global_state.save(filepath="state")

        assert global_state.get_build_packages() == build_packages
        assert global_state.get_build_snaps() == build_snaps

        new_packages = ["new-pkg1", "new-pkg2"]
        new_snaps = ["new-snap1", "new-snap2"]
        global_state = GlobalState.load(filepath="state")
        global_state.append_build_packages(new_packages)
        global_state.append_build_snaps(new_snaps)

        assert global_state.get_build_packages(
        ) == build_packages + new_packages

        assert global_state.get_build_snaps() == build_snaps + new_snaps
    def test_save(self):
        global_state = GlobalState()
        global_state.append_build_packages(self.build_packages)
        global_state.append_build_snaps(self.build_snaps)

        global_state.save(filepath="state")

        build_packages_str = ", ".join(self.build_packages)
        build_snaps_str = ", ".join(self.build_snaps)

        self.assertThat(
            "state",
            FileContains(
                dedent("""\
                    !GlobalState
                    assets:
                      build-packages: [{}]
                      build-snaps: [{}]
                    """).format(build_packages_str, build_snaps_str)),
        )
Exemple #6
0
    def test_save_load_and_append(self):
        global_state = GlobalState()
        global_state.append_build_packages(self.build_packages)
        global_state.append_build_snaps(self.build_snaps)
        global_state.save(filepath="state")

        self.assertThat(global_state.get_build_packages(), Equals(self.build_packages))
        self.assertThat(global_state.get_build_snaps(), Equals(self.build_snaps))

        new_packages = ["new-pkg1", "new-pkg2"]
        new_snaps = ["new-snap1", "new-snap2"]
        global_state = GlobalState.load(filepath="state")
        global_state.append_build_packages(new_packages)
        global_state.append_build_snaps(new_snaps)

        self.assertThat(
            global_state.get_build_packages(),
            Equals(self.build_packages + new_packages),
        )
        self.assertThat(
            global_state.get_build_snaps(), Equals(self.build_snaps + new_snaps)
        )
Exemple #7
0
    def test_save(self, tmp_work_path, build_packages, build_snaps,
                  required_grade):
        global_state = GlobalState()
        global_state.append_build_packages(build_packages)
        global_state.append_build_snaps(build_snaps)
        global_state.set_required_grade(required_grade)

        global_state.save(filepath="state")

        prepend = "  - "

        if build_packages:
            build_packages = "\n" + "\n".join(
                ["{}{}".format(prepend, p) for p in build_packages])
        else:
            build_packages = " []"

        if build_snaps:
            build_snaps = "\n" + "\n".join(
                ["{}{}".format(prepend, p) for p in build_snaps])
        else:
            build_snaps = " []"

        if required_grade:
            required_grade = required_grade
        else:
            required_grade = "null"

        with open("state") as state_file:
            state_file_contents = state_file.read()
            assert (state_file_contents == dedent("""\
                    !GlobalState
                    assets:
                      build-packages:{}
                      build-snaps:{}
                      required-grade: {}
                    """).format(build_packages, build_snaps, required_grade))