Example #1
0
    def test_complicated(self):
        # Given
        install_requires = (
            ("numpy", (("^= 1.8.0",),)),
            ("requests", ((">= 0.2",),)),
            ("zope", (("*",),)))
        conflicts = (
            ("bokeh", (('',),)),
            ("requests", ((">= 0.2.5", "< 0.4"),)))
        provides = (
            ("bokeh", (('*',),)),)
        expected = PackageMetadata(
            u"bokeh_git", V("0.2.0-3"),
            install_requires=install_requires,
            conflicts=conflicts,
            provides=provides)
        parser = PrettyPackageStringParser(V)

        # When
        s = '; '.join((
            "bokeh_git 0.2.0-3",
            "install_requires (numpy ^= 1.8.0, requests >= 0.2, zope *)",
            "conflicts (bokeh, requests >= 0.2.5, requests < 0.4)",
            "provides (bokeh *)",
        ))
        result = parser.parse_to_package(s)

        # Then
        self.assertEqual(result, expected)
    def test_to_legacy_constraints(self):
        # Given
        parser = PrettyPackageStringParser(V)
        package_string = "numpy 1.8.0-1; depends (nose == 1.3.4-1)"

        # When
        name, version, constraints = parser.parse_to_legacy_constraints(package_string)

        # Then
        self.assertEqual(name, "numpy")
        self.assertEqual(version, V("1.8.0-1"))
        self.assertEqual(constraints, ("nose 1.3.4-1",))

        # Given
        package_string = "numpy 1.8.0-1; depends (nose ^= 1.3.4)"

        # When
        name, version, constraints = parser.parse_to_legacy_constraints(package_string)

        # Then
        self.assertEqual(name, "numpy")
        self.assertEqual(version, V("1.8.0-1"))
        self.assertEqual(constraints, ("nose 1.3.4",))

        # Given
        package_string = "numpy 1.8.0-1; depends (nose)"

        # When
        name, version, constraints = parser.parse_to_legacy_constraints(package_string)

        # Then
        self.assertEqual(name, "numpy")
        self.assertEqual(version, V("1.8.0-1"))
        self.assertEqual(constraints, ("nose",))
    def test_invalid_formats(self):
        # Given
        parser = PrettyPackageStringParser(V)
        package_string = ""
        r_message = "Invalid preamble: "

        # When
        with self.assertRaisesRegexp(ValueError, r_message):
            parser.parse(package_string)

        # Given
        package_string = "numpy"
        r_message = "Invalid preamble: 'numpy'"

        # When
        with self.assertRaisesRegexp(ValueError, r_message):
            parser.parse(package_string)

        # Given
        package_string = "numpy 1.8.0-1; depends (nose 1.3.2)"
        r_message = "Invalid requirement block: "

        # When
        with self.assertRaisesRegexp(SolverException, r_message):
            parser.parse(package_string)

        # Given
        package_string = "numpy 1.8.0-1; conflicts (nose 1.3.2)"
        r_message = "Invalid constraint block: 'conflicts \(nose 1.3.2\)'"

        # When
        with self.assertRaisesRegexp(ValueError, r_message):
            parser.parse(package_string)
    def test_simple(self):
        # Given
        s = u"numpy 1.8.1; depends (MKL ^= 10.3)"
        parser = PrettyPackageStringParser(EnpkgVersion.from_string)

        # When
        package = parser.parse_to_package(s)

        # Then
        self.assertEqual(package.name, "numpy")
        self.assertEqual(package.dependencies, ("MKL 10.3",))
Example #5
0
    def test_with_conflicts(self):
        # Given
        s = u"numpy 1.8.1; conflicts (MKL <= 10.3)"
        parser = PrettyPackageStringParser(V)

        # When
        package = parser.parse_to_package(s)

        # Then
        self.assertEqual(package.name, "numpy")
        self.assertEqual(package.version, V('1.8.1'))
        self.assertEqual(package.conflicts, (("MKL", (("<= 10.3",),)),))
Example #6
0
    def test_with_depends(self):
        # Given
        s = u"numpy 1.8.1; depends (MKL ^= 10.3)"
        parser = PrettyPackageStringParser(V)

        # When
        package = parser.parse_to_package(s)

        # Then
        self.assertEqual(package.name, "numpy")
        self.assertEqual(package.version, V('1.8.1'))
        self.assertEqual(package.install_requires, (("MKL", (("^= 10.3",),)),))
Example #7
0
    def test_simple(self):
        # Given
        s = u"zope.deprecated_ 2"
        parser = PrettyPackageStringParser(V)

        # When
        package = parser.parse_to_package(s)

        # Then
        self.assertEqual(package.name, "zope.deprecated_")
        self.assertEqual(package.version, V('2'))
        self.assertEqual(package.install_requires, ())
    def test_no_dependencies(self):
        # Given
        parser = PrettyPackageStringParser(V)
        package_string = "numpy 1.8.0-1"

        # When
        name, version, constraints = parser.parse(package_string)

        # Then
        self.assertEqual(name, "numpy")
        self.assertEqual(version, V("1.8.0-1"))
        six.assertCountEqual(self, constraints, set())
    def test_simple(self):
        # Given
        parser = PrettyPackageStringParser(V)
        package_string = "numpy 1.8.0-1; depends (nose == 1.3.4-1)"

        # When
        name, version, constraints = parser.parse(package_string)

        # Then
        self.assertEqual(name, "numpy")
        self.assertEqual(version, V("1.8.0-1"))
        self.assertTrue("nose" in constraints)
        self.assertEqual(constraints["nose"], set((Equal(V("1.3.4-1")),)))
Example #10
0
    def test_with_provides(self):
        # Given
        s = u"numpy 1.8.1-4; provides (numeric)"
        parser = PrettyPackageStringParser(V)

        # When
        package = parser.parse_to_package(s)

        # Then
        self.assertEqual(package.name, "numpy")
        self.assertEqual(package.version, V('1.8.1-4'))
        self.assertEqual(package.provides,
                         (('numpy', (('*',),)),
                          ("numeric", (("",),))))
Example #11
0
    def test_unversioned(self):
        # Given
        parse = PrettyPackageStringParser(V).parse
        package_string = "numpy 1.8.0-1; depends (nose, matplotlib == 1.3.2-1)"

        # When
        package = parse(package_string)
        name = package['distribution']
        version = package['version']
        install_requires = dict(package['install_requires'])

        # Then
        self.assertEqual(name, "numpy")
        self.assertEqual(version, V("1.8.0-1"))
        self.assertTrue("nose" in install_requires)
        self.assertEqual(install_requires["nose"], (('',),))
        self.assertEqual(install_requires["matplotlib"], (('== 1.3.2-1',),))

        # Given
        package_string = "numpy 1.8.0-1; depends (nose *, zope == 1.3.2-1)"

        # When
        package = parse(package_string)
        name = package['distribution']
        version = package['version']
        install_requires = dict(package['install_requires'])

        # Then
        self.assertEqual(name, "numpy")
        self.assertEqual(version, V("1.8.0-1"))
        self.assertTrue("nose" in install_requires)
        self.assertEqual(install_requires["nose"], (('*',),))
        self.assertEqual(install_requires["zope"], (('== 1.3.2-1',),))
Example #12
0
    def test_pretty_package_parse(self):
        # Given
        parser = PrettyPackageStringParser(EnpkgVersion.from_string)
        package_strings = self.SCARY_PACKAGE_STRINGS

        # When
        for package_string in package_strings:
            package = parser.parse_to_package(package_string)
            expected = tuple(package_string.split())
            result = (package.name, str(package.version))

            # Then
            self.assertEqual(expected, result)

        # Given
        package_strings = self.UNACCEPTABLE_PACKAGE_STRINGS

        # When
        for package_string in package_strings:
            # Then
            with self.assertRaises(ValueError):
                parser.parse_to_package(package_string)
Example #13
0
    def test_invalid_formats(self):
        # Given
        parse = PrettyPackageStringParser(V).parse
        package_string = ""
        r_message = "Invalid preamble: "

        # Then
        with self.assertRaisesRegexp(ValueError, r_message):
            parse(package_string)

        # Given
        package_string = "numpy"
        r_message = "Invalid preamble: 'numpy'"

        # Then
        with self.assertRaisesRegexp(ValueError, r_message):
            parse(package_string)

        # Given
        package_string = "numpy1.8.0-1"
        r_message = ("Invalid preamble: ")

        # Then
        with self.assertRaisesRegexp(ValueError, r_message):
            parse(package_string)

        # Given
        package_string = "numpy 1.8.0-1 depends (nose >= 1.3.2)"
        r_message = ("Invalid preamble: ")

        # Then
        with self.assertRaisesRegexp(ValueError, r_message):
            parse(package_string)

        # Given
        package_string = "numpy; depends (nose >= 1.3.2)"
        r_message = ("Invalid preamble: ")

        # Then
        with self.assertRaisesRegexp(ValueError, r_message):
            parse(package_string)

        # Given
        package_string = "numpy 1.8.0-1; disparages (nose >= 1.3.2)"
        r_message = ("Invalid package string. "
                     "Unknown constraint kind: 'disparages'")

        # When
        with self.assertRaisesRegexp(ValueError, r_message):
            parse(package_string)
Example #14
0
    def test_no_constraints(self):
        # Given
        parse = PrettyPackageStringParser(V).parse
        package_string = "numpy 1.8.0-1"

        # When
        package = parse(package_string)
        name = package['distribution']
        version = package['version']

        # Then
        self.assertEqual(name, "numpy")
        self.assertEqual(version, V("1.8.0-1"))
        self.assertEqual(len(package), 2)
Example #15
0
    def test_special_characters(self):
        # Given
        parse = PrettyPackageStringParser(V).parse
        package_string = "shiboken_debug 1.2.2-5"

        # When
        package = parse(package_string)
        name = package['distribution']
        version = package['version']

        # Then
        self.assertEqual(name, "shiboken_debug")
        self.assertEqual(version, V("1.2.2-5"))

        # Given
        parse = PrettyPackageStringParser(V).parse
        package_string = '; '.join((
            "scikits.image 0.10.0-1",
            "depends (scipy ^= 0.14.0, pil, zope.distribution *)"
        ))
        r_install_requires = (
            ('pil', (('',),)),
            ('scipy', (('^= 0.14.0',),)),
            ('zope.distribution', (('*',),))
        )

        # When
        package = parse(package_string)
        name = package['distribution']
        version = package['version']
        install_requires = package['install_requires']

        # Then
        self.assertEqual(name, "scikits.image")
        self.assertEqual(version, V("0.10.0-1"))
        self.assertEqual(install_requires, r_install_requires)
Example #16
0
    def test_complicated(self):
        # Given
        parse = PrettyPackageStringParser(V).parse
        package_string = '; '.join((
            "bokeh 0.2.0-3",
            "depends (numpy ^= 1.8.0, MKL == 10.3, requests >= 0.2)",
            # Intentional typo
            "conflits (bokeh-git, requests ^= 0.2.5, requests > 0.4)",
        ))
        r_message = ("Invalid package string. "
                     "Unknown constraint kind: 'conflits'")

        # Then
        with self.assertRaisesRegexp(ValueError, r_message):
            parse(package_string)

        # Given
        package_string = '; '.join((
            "bokeh_git 0.2.0-3",
            "install_requires (zope *, numpy ^= 1.8.0, requests >= 0.2)",
            "conflicts (requests ^= 0.2.5, requests > 0.4, bokeh)",
            "provides (webplot ^= 0.1, bokeh)",
        ))
        r_install_requires = (
            ("numpy", (("^= 1.8.0",),)),
            ("requests", ((">= 0.2",),)),
            ("zope", (("*",),)))
        r_conflicts = (
            ("bokeh", (('',),)),
            ("requests", (("^= 0.2.5", "> 0.4"),)))
        r_provides = (
            ("bokeh", (('',),)),
            ("webplot", (("^= 0.1",),)))

        # When
        package = parse(package_string)
        name = package['distribution']
        version = package['version']
        install_requires = package['install_requires']
        conflicts = package['conflicts']
        provides = package['provides']

        # Then
        self.assertEqual(name, "bokeh_git")
        self.assertEqual(version, V("0.2.0-3"))
        self.assertEqual(install_requires, r_install_requires)
        self.assertEqual(conflicts, r_conflicts)
        self.assertEqual(provides, r_provides)
Example #17
0
    def test_multiple(self):
        # Given
        parse = PrettyPackageStringParser(V).parse
        package_string = "numpy 1.8.0-1; depends (nose => 1.3, nose < 1.4)"

        # When
        package = parse(package_string)
        name = package['distribution']
        version = package['version']
        install_requires = dict(package['install_requires'])

        # Then
        self.assertEqual(name, "numpy")
        self.assertEqual(version, V("1.8.0-1"))
        self.assertIn("nose", install_requires)
        self.assertEqual(install_requires["nose"], (('=> 1.3', '< 1.4'),))
Example #18
0
    def test_conflicts_simple(self):
        # Given
        parse = PrettyPackageStringParser(V).parse
        package_string = "numpy 1.8.0-1; conflicts (browsey ^= 1.3.0)"

        # When
        package = parse(package_string)
        name = package['distribution']
        version = package['version']
        conflicts = dict(package['conflicts'])

        # Then
        self.assertEqual(name, "numpy")
        self.assertEqual(version, V("1.8.0-1"))
        self.assertTrue("browsey" in conflicts)
        self.assertEqual(conflicts["browsey"], (('^= 1.3.0',),))
Example #19
0
    def test_depends_simple(self):
        # Given
        parse = PrettyPackageStringParser(V).parse
        package_string = "numpy 1.8.0-1; depends (nose == 1.3.4-1)"

        # When
        package = parse(package_string)
        name = package['distribution']
        version = package['version']
        install_requires = dict(package['install_requires'])

        # Then
        self.assertEqual(name, "numpy")
        self.assertEqual(version, V("1.8.0-1"))
        self.assertTrue("nose" in install_requires)
        self.assertEqual(install_requires["nose"], (('== 1.3.4-1',),))