Ejemplo n.º 1
0
    def test_parsing(self):
        v = Version("1.2.3-dev.90.80-dev2+build.b1.b2")
        self.assertEqual(v.prerelease, "dev.90.80-dev2")
        self.assertEqual(v.build, "build.b1.b2")

        v = Version("1.2.305-dev4")
        self.assertEqual(v.prerelease, "dev4")
        self.assertEqual(v.build, "")

        v = Version("1.2.305+dev4")
        self.assertEqual(v.prerelease, "")
        self.assertEqual(v.build, "dev4")
Ejemplo n.º 2
0
def check_min_vs(conanfile, version):
    """ this is a helper method to allow the migration of 1.X->2.0 and VisualStudio->msvc settings
    withoug breaking recipes
    The legacy "Visual Studio" with different toolset is not managed, not worth the complexity
    """
    compiler = conanfile.settings.get_safe("compiler")
    compiler_version = None
    if compiler == "Visual Studio":
        compiler_version = conanfile.settings.get_safe("compiler.version")
        compiler_version = {"17": "193",
                            "16": "192",
                            "15": "191",
                            "14": "190",
                            "12": "180",
                            "11": "170"}.get(compiler_version)
    elif compiler == "msvc":
        compiler_version = conanfile.settings.get_safe("compiler.version")
        compiler_update = conanfile.settings.get_safe("compiler.update")
        if compiler_version and compiler_update is not None:
            compiler_version += ".{}".format(compiler_update)

    if compiler_version and Version(compiler_version) < version:
        msg = "This package doesn't work with VS compiler version '{}'" \
              ", it requires at least '{}'".format(compiler_version, version)
        raise ConanInvalidConfiguration(msg)
Ejemplo n.º 3
0
 def test_valid_values(self):
     for v_str in [
             "1.2.3", "1.2.3-dev90", "1.2.3+dev90", "1.2.3-dev90+more",
             "1.2.3-dev90+a.b"
     ]:
         v = Version(v_str)
         self.assertEqual(v.major, "1")
         self.assertEqual(v.minor, "2")
         self.assertEqual(v.patch, "3")
Ejemplo n.º 4
0
    def test_gt(self):
        self.assertTrue(Version("1.2.3") > "1.2.2")

        self.assertTrue(Version.loose)
        self.assertTrue(Version("1.2") > "1")
        self.assertTrue(Version("1.2") > Version("1"))

        self.assertFalse(Version("1.0") > "1")
        self.assertFalse(Version("1.0.0") > "1")
        self.assertFalse(Version("1") > "1.0")
        self.assertFalse(Version("1") > "1.0.0")
Ejemplo n.º 5
0
    def test_migrations_matches_config(self):
        # Check that the current settings matches what is stored in the migrations file
        current_settings = get_default_settings_yml()
        v = Version(__version__)
        var_name = "settings_{}".format("_".join([v.major, v.minor, v.patch]))

        self.assertTrue(hasattr(migrations_settings, var_name),
                        "Migrations var '{}' not found".format(var_name))
        migrations_settings_content = getattr(migrations_settings, var_name)
        assert current_settings == migrations_settings_content
Ejemplo n.º 6
0
    def test_convert_str(self):
        # Check that we are calling the string method
        class A(object):
            def __str__(self):
                return "1.2.3"

        v = Version(A())
        self.assertEqual(v.major, "1")
        self.assertEqual(v.minor, "2")
        self.assertEqual(v.patch, "3")
Ejemplo n.º 7
0
    def test_valid_loose(self):
        self.assertTrue(Version.loose)

        # These versions are considered valid with loose validation
        self.assertTrue(Version.loose)
        v = Version("1.2")
        self.assertEqual(v.major, "1")
        self.assertEqual(v.minor, "2")
        self.assertEqual(v.patch, "0")

        v = Version("1")
        self.assertEqual(v.major, "1")
        self.assertEqual(v.minor, "0")
        self.assertEqual(v.patch, "0")

        v = Version(" 1a")
        self.assertEqual(v.major, "1")
        self.assertEqual(v.minor, "0")
        self.assertEqual(v.patch, "0")
Ejemplo n.º 8
0
    def test_compare(self):
        self.assertTrue(Version("1.2.3") == "1.2.3")
        self.assertTrue(Version("1.2.3") == Version("1.2.3"))

        self.assertTrue(Version.loose)
        self.assertTrue(Version("234") == "234")
        self.assertTrue(Version("234") == Version("234"))
Ejemplo n.º 9
0
    def is_there_var_for_settings_previous_version_test(self):
        from conans import __version__ as current_version

        tmp = Version(current_version)
        if int(tmp.minor) == 0:
            return unittest.skip("2.0, this will make sense for 2.1")
        if int(tmp.patch) > 0:
            previous_version = "{}.{}.{}".format(tmp.major, tmp.minor, int(tmp.patch) - 1)
        else:
            previous_version = "{}.{}.0".format(tmp.major, int(tmp.minor) - 1)

        from conans.client import migrations_settings
        var_name = "settings_{}".format(previous_version.replace(".", "_"))
        self.assertTrue(any([i for i in dir(migrations_settings) if i == var_name]),
                        "Introduce the previous settings.yml file in the 'migrations_settings.yml")
Ejemplo n.º 10
0
    def test_compare(self):
        # prerelease is taken into account
        self.assertTrue(Version("1.2.3-dev90") != "1.2.3")
        self.assertTrue(Version("1.2.3-dev90") < "1.2.3")
        self.assertTrue(Version("1.2.3-dev90") < Version("1.2.3"))

        # build is not taken into account
        self.assertTrue(Version("1.2") == Version("1.2+dev0"))
        self.assertFalse(Version("1.2") > Version("1.2+dev0"))
        self.assertFalse(Version("1.2") < Version("1.2+dev0"))

        # Unknown release field, not fail (loose=True) and don't affect compare
        self.assertTrue(Version.loose)
        self.assertTrue(Version("1.2.3.4") == Version("1.2.3"))
Ejemplo n.º 11
0
 def test_invalid_message(self):
     with six.assertRaisesRegex(self, ConanException,
                                "Invalid version 'not-valid'"):
         Version("not-valid")