Beispiel #1
0
    def test_add_reduce_failed(self):
        """Test than when adding two incompatible requirements
        together an error is raised.
        """
        TESTS = [
            ['zeam ==2.4', 'zeam ==1.1'],
            ['zeam ==2.4', 'zeam !=2.4'],
            ['zeam ==2.4', 'zeam <=1.1'],
            ['zeam ==2.4', 'zeam >=4.1'],
            ['zeam !=2.4', 'zeam ==2.4'],
            ['zeam >=2.4', 'zeam <=1.1'],
            ['zeam >=2.4', 'zeam ==1.1'],
            ['zeam <=2.4', 'zeam >=5.1'],
            ['zeam <=2.4', 'zeam ==5.1'],
            ['zeam <=2.4', 'zeam >= latest'],
            ]

        for first, second in TESTS:
            req_first = Requirement.parse(first)
            req_second = Requirement.parse(second)

            try:
                req_first + req_second
            except IncompatibleVersion:
                continue
            else:
                self.fail(u'"%s" + "%s" should not work' % (first, second))
Beispiel #2
0
    def test_parse(self):
        """Test requirement parsing and printing
        """
        req = Requirement.parse('test.software')
        self.assertEqual(req.name, 'test.software')
        self.assertEqual(req.versions, [])
        self.assertEqual(req.extras, set())
        self.assertEqual(str(req), 'test.software')

        req = Requirement.parse('MySoft ==2.3, <=2.4')
        self.assertEqual(req.name, 'MySoft')
        self.assertEqual(req.extras, set())
        self.assertEqual(len(req.versions), 2)
        self.assertEqual(str(req), 'MySoft==2.3,<=2.4')

        req = Requirement.parse('Zope2>=2.12.3dev')
        self.assertEqual(req.name, 'Zope2')
        self.assertEqual(len(req.versions), 1)
        self.assertEqual(str(req.versions[0][1]), '2.12.3dev')
        self.assertEqual(str(req), 'Zope2>=2.12.3dev')

        req = Requirement.parse('python-memcached >= 1.0, ==dev')
        self.assertEqual(req.name, 'python-memcached')
        self.assertEqual(len(req.versions), 1)
        self.assertEqual(str(req.versions[0][1]), '1.0')
        self.assertEqual(str(req), 'python-memcached>=1.0')
Beispiel #3
0
    def test_add_extras(self):
        """Test than extras are keeping and extending while adding
        two requirements together.
        """
        TESTS = [
            ['zeam[nuclear] <=2.1', 'zeam >=1.9',
             'zeam[nuclear]>=1.9,<=2.1'],
            ['zeam <=2.1', 'zeam[nuclear] >=1.9',
             'zeam[nuclear]>=1.9,<=2.1'],
            ['zeam[nuclear] <=2.1', 'zeam[nuclear,web] >=1.9',
             'zeam[nuclear,web]>=1.9,<=2.1'],
            ['zeam[nuclear] <=2.1', 'zeam[web,tests]',
             'zeam[nuclear,tests,web]<=2.1'],
            ]

        for index, test_entry in enumerate(TESTS):
            first, second, expected = test_entry
            req_first = Requirement.parse(first)
            req_second = Requirement.parse(second)

            req_result = req_first + req_second
            result = str(req_result)
            self.assertEqual(
                result, expected,
                msg=u'"%s" + "%s" != "%s" (got %s, test %d)' % (
                    first, second, expected, result, index))
Beispiel #4
0
 def test_unique(self):
     """Test is_unique on a requirement.
     """
     req = Requirement.parse('MySoft >=2.0, <=2.4')
     self.assertFalse(req.is_unique())
     req = Requirement.parse('MySoft')
     self.assertFalse(req.is_unique())
     req = Requirement.parse('MySoft ==3.0')
     self.assertTrue(req.is_unique())
     req = Requirement.parse('MySoft ==3.0,>=2.0')
     self.assertTrue(req.is_unique())
Beispiel #5
0
    def test_add(self):
        """Test adding two requirements together
        """
        req_one = Requirement.parse("zeam")
        req_two = Requirement.parse("zeam <= 2.1")
        req_other = Requirement.parse("something.else == 51.0")

        self.assertRaises(InvalidRequirement, operator.add, req_one, 1)
        self.assertRaises(InvalidRequirement, operator.add, req_one, req_other)

        req_result = req_one + req_two
        self.assertEqual(str(req_result), "zeam<=2.1")
Beispiel #6
0
    def test_hash(self):
        """Test that requirements are hashable
        """
        req_origin = Requirement.parse("zeam >= 42.0")
        req_lookup = Requirement.parse("zeam >= 42.0")
        req_other = Requirement.parse("zeam >= 12.0")
        self.assertEqual(req_origin, req_lookup)
        self.assertEqual(hash(req_origin), hash(req_lookup))
        self.assertNotEqual(req_origin, req_other)
        self.assertNotEqual(hash(req_origin), hash(req_other))

        data = {}
        data[req_origin] = 10
        self.assertEqual(data.get(req_lookup, None), 10)
        self.assertEqual(data.get(req_other, None), None)
Beispiel #7
0
    def test_add_reduce(self):
        """Test than when adding two requirements together
        version are simplified.
        """
        TESTS = [
            ['zeam ==1.1', 'zeam ==1.1', 'zeam==1.1'],
            ['zeam ==1.1', 'zeam >=0.9', 'zeam==1.1'],
            ['zeam ==1.1', 'zeam >=1.1', 'zeam==1.1'],
            ['zeam ==1.1', 'zeam <=9.1', 'zeam==1.1'],
            ['zeam ==1.1', 'zeam <=1.1', 'zeam==1.1'],
            ['zeam !=1.1', 'zeam !=1.1', 'zeam!=1.1'],
            ['zeam !=3.1', 'zeam <=1.1', 'zeam<=1.1'],
            ['zeam !=3.1', 'zeam <=3.1', 'zeam<=3.1,!=3.1'],
            ['zeam !=3.1', 'zeam <=4.1', 'zeam!=3.1,<=4.1'],
            ['zeam !=3.1', 'zeam >=4.1', 'zeam>=4.1'],
            ['zeam !=3.1', 'zeam >=1.1', 'zeam>=1.1,!=3.1'],
            ['zeam !=3.1', 'zeam >=3.1', 'zeam>=3.1,!=3.1'],
            ['zeam >=2.4,>=4.2', 'zeam >=3.1', 'zeam>=4.2'],
            ['zeam >=2.4', 'zeam !=0.4', 'zeam>=2.4'],
            ['zeam >=2.4', 'zeam !=4.4', 'zeam>=2.4,!=4.4'],
            ['zeam >=2.4', 'zeam !=2.4', 'zeam!=2.4,>=2.4'],
            ['zeam >=2.4', 'zeam ==4.4', 'zeam==4.4'],
            ['zeam >=4.4', 'zeam ==4.4', 'zeam==4.4'],
            ['zeam >=2.4', 'zeam <=4.4', 'zeam>=2.4,<=4.4'],
            ['zeam >=2.4', 'zeam <=2.4', 'zeam<=2.4,>=2.4'],
            ['zeam <=2.4', 'zeam ==1.4', 'zeam==1.4'],
            ['zeam <=1.4', 'zeam ==1.4', 'zeam==1.4'],
            ['zeam <=2.4', 'zeam !=1.4', 'zeam!=1.4,<=2.4'],
            ['zeam <=2.4', 'zeam !=2.4', 'zeam!=2.4,<=2.4'],
            ['zeam <=2.4', 'zeam !=4.4', 'zeam<=2.4'],
            ['zeam <=2.4', 'zeam >=1.4', 'zeam>=1.4,<=2.4'],
            ['zeam <=2.4', 'zeam >=2.4', 'zeam>=2.4,<=2.4'],
            ]

        for index, test_entry in enumerate(TESTS):
            first, second, expected = test_entry
            req_first = Requirement.parse(first)
            req_second = Requirement.parse(second)

            req_result = req_first + req_second
            result = str(req_result)
            self.assertEqual(
                result, expected,
                msg=u'"%s" + "%s" != "%s" (got %s, test %d)' % (
                    first, second, expected, result, index))
Beispiel #8
0
    def test_parse_extras(self):
        """Test requirement parsing and printing with extras
        """
        req = Requirement.parse('CoolSoft[zca]')
        self.assertEqual(req.name, 'CoolSoft')
        self.assertEqual(req.extras, set(['zca']))
        self.assertEqual(req.versions, [])
        self.assertEqual(str(req), 'CoolSoft[zca]')

        req = Requirement.parse('NewSoft [testing,zope.testing , web]')
        self.assertEqual(req.name, 'NewSoft')
        self.assertEqual(req.extras, set(['testing', 'zope.testing', 'web']))
        self.assertEqual(req.versions, [])
        self.assertEqual(str(req), 'NewSoft[testing,web,zope.testing]')

        req = Requirement.parse('NewSoft [zope.testing , web] <=2.4, >=1.0')
        self.assertEqual(req.name, 'NewSoft')
        self.assertEqual(req.extras, set(['zope.testing', 'web']))
        self.assertEqual(len(req.versions), 2)
        self.assertEqual(str(req), 'NewSoft[web,zope.testing]<=2.4,>=1.0')
Beispiel #9
0
    def test_match(self):
        """Test matching a requirement to a release
        """
        req = Requirement.parse('MySoft >=2.0, <=2.4')
        release = Release('YourSoft', '2.1')
        self.assertFalse(req.match(release))

        release = Release('MySoft', '2.1')
        self.assertTrue(req.match(release))

        release = Release('MySoft', '1.0')
        self.assertFalse(req.match(release))