示例#1
0
    def test_applicable_normal(self):
        # This is the expected scenario: each updater bumps exactly one
        # version; we have an unbroken chain of updaters; the only variance is
        # in the version at which we start (version saved in the input file).
        update._register("1.1", "1.2", lambda config: config + ["to 1.2"])
        update._register("1.2", "1.3", lambda config: config + ["to 1.3"])
        update._register("1.3", "1.4", lambda config: config + ["to 1.4"])

        # already current
        triples = update._get_applicable_updaters("NAME", "1.4")
        assert not triples

        # one previous version, need one updater
        triples = update._get_applicable_updaters("NAME", "1.3")
        assert_equals(len(triples), 1)
        assert_equals(triples[0][:2], ("1.3", "1.4"))

        # two versions older, need two updaters
        triples = update._get_applicable_updaters("NAME", "1.2")
        assert_equals(len(triples), 2)
        assert_equals(triples[0][:2], ("1.2", "1.3"))
        assert_equals(triples[1][:2], ("1.3", "1.4"))

        # three versions older, need three updaters
        triples = update._get_applicable_updaters("NAME", "1.1")
        assert_equals(len(triples), 3)
        assert_equals(triples[0][:2], ("1.1", "1.2"))
        assert_equals(triples[1][:2], ("1.2", "1.3"))
        assert_equals(triples[2][:2], ("1.3", "1.4"))

        # verify that the functions we registered are the ones we get back
        config = []
        for _, _, func in triples:
            config = func(config)
        assert_equals(config, ["to 1.2", "to 1.3", "to 1.4"])

        # way way old, so sorry
        with exc(update.UpdateError):
            triples = update._get_applicable_updaters("NAME", "1.0")

        # introduce a shortcut converter from 1.2 to 1.4
        update._register("1.2", "1.4", lambda config: config + ["jump 1.4"])

        # conversion from 1.2 should now always take the shortcut
        triples = update._get_applicable_updaters("NAME", "1.1")
        assert_equals(len(triples), 2)
        assert_equals(triples[0][:2], ("1.1", "1.2"))
        assert_equals(triples[1][:2], ("1.2", "1.4"))

        # whoops, suddenly we're trying to reach a version for which we have
        # no updater
        update.AUTOBUILD_CONFIG_VERSION = "1.5"

        with exc(update.UpdateError):
            triples = update._get_applicable_updaters("NAME", "1.1")
示例#2
0
    def test_applicable_loop(self):
        update._register("1.1", "1.2", lambda config: config + ["to 1.2"])
        update._register("1.2", "1.3", lambda config: config + ["to 1.3"])
        update._register("1.3", "1.1", lambda config: config + ["back to 1.1"])

        with exc(AssertionError, "loop"):
            triples = update._get_applicable_updaters("NAME", "1.1")
示例#3
0
 def test_autobuild_build(self):
     # Make sure the verbose 'new requirement' message is produced when the
     # missing key is version_file with an older version config file. The
     # (?s) flag allows '.' to match newline, important because 'new
     # requirement' may be on a different line of the exception message
     # than the attribute name version_file.
     with exc(BuildError, "(?is)version_file.*new requirement"):
         build('build', '--config-file=' + self.tmp_file, '--id=123456')
示例#4
0
    def test_applicable_stuck(self):
        # This test constructs a chain of updaters that could be resolved by a
        # graph search, but which suffices to confuse our "always take
        # shortcuts" logic. If we ever introduce a graph search, we expect
        # this test to start failing because the call should start working.
        update._register("1.1", "1.2", lambda config: config + ["to 1.2"])
        update._register("1.1", "1.3", lambda config: config + ["to 1.3"])
        update._register("1.2", "1.4", lambda config: config + ["to 1.4"])

        with exc(update.UpdateError):
            triples = update._get_applicable_updaters("NAME", "1.1")
示例#5
0
    def test_convert(self):
        # normal type registry
        update._register("1.1", "1.2", lambda config: self.track_config(config, "to 1.2"))
        update._register("1.2", "1.3", lambda config: self.track_config(config, "to 1.3"))
        update._register("1.3", "1.4", lambda config: self.track_config(config, "to 1.4"))

        # config too old to even have a version key
        with exc(update.UpdateError):
            config, orig_ver = update.convert_to_current("NAME", {})

        # current config needs no update
        config, orig_ver = update.convert_to_current("NAME", dict(version="1.4"))
        assert_equals(orig_ver, None)
        assert "track" not in config, "updater called on current config"

        # oldest supported config gets all updaters
        config, orig_ver = update.convert_to_current("NAME", dict(version="1.1"))
        assert_equals(orig_ver, "1.1")
        assert "track" in config, "updater not called on old config"
        assert_equals(config["track"], ["to 1.2", "to 1.3", "to 1.4"])
        assert_equals(config["version"], "1.4")
示例#6
0
 def test_autobuild_build(self):
     with exc(common.AutobuildError, "version_file"):
         build('build', '--config-file=' + self.tmp_file, '--id=123456')
示例#7
0
 def test_autobuild_build(self):
     # Make sure the verbose 'new requirement' message isn't produced with
     # a current format config file.
     with exc(BuildError, "version_file", without="(?i)new requirement"):
         build('build', '--config-file=' + self.tmp_file, '--id=123456')
示例#8
0
 def test_autobuild_build(self):
     # Make sure the verbose 'new requirement' message is only produced
     # when the missing key is in fact version_file, especially with an
     # older version config file.
     with exc(BuildError, "name", without="(?i)new requirement"):
         build('build', '--config-file=' + self.tmp_file, '--id=123456')