aboutsummaryrefslogtreecommitdiff
blob: 833fd4978321f6f470ee4b54a5e1ac1efa31bda2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python
#
# Copyright(c) 2009-2010, Gentoo Foundation
#
# Licensed under the GNU General Public License, v2
#
# $Header$

import unittest
from test import test_support

from gentoolkit.cpv import *

class TestGentoolkitCPV(unittest.TestCase):

	def assertEqual2(self, o1, o2):
		# logic bugs hidden behind short circuiting comparisons for metadata
		# is why we test the comparison *both* ways.
		self.assertEqual(o1, o2)
		c = cmp(o1, o2)
		self.assertEqual(c, 0,
			msg="checking cmp for %r, %r, aren't equal: got %i" % (o1, o2, c))
		self.assertEqual(o2, o1)
		c = cmp(o2, o1)
		self.assertEqual(c, 0,
			msg="checking cmp for %r, %r,aren't equal: got %i" % (o2, o1, c))

	def assertNotEqual2(self, o1, o2):
		# is why we test the comparison *both* ways.
		self.assertNotEqual(o1, o2)
		c = cmp(o1, o2)
		self.assertNotEqual(c, 0,
			msg="checking cmp for %r, %r, not supposed to be equal, got %i"
				% (o1, o2, c))
		self.assertNotEqual(o2, o1)
		c = cmp(o2, o1)
		self.assertNotEqual(c, 0,
			msg="checking cmp for %r, %r, not supposed to be equal, got %i"
				% (o2, o1, c))

	def test_comparison(self):
		self.assertEqual2(CPV('pkg'), CPV('pkg'))
		self.assertNotEqual2(CPV('pkg'), CPV('pkg1'))
		self.assertEqual2(CPV('cat/pkg'), CPV('cat/pkg'))
		self.assertNotEqual2(CPV('cat/pkg'), CPV('cat/pkgb'))
		self.assertNotEqual2(CPV('cata/pkg'), CPV('cat/pkg'))
		self.assertEqual2(CPV('cat/pkg-0.1'), CPV('cat/pkg-0.1'))
		self.assertNotEqual2(CPV('cat/pkg-1.0'), CPV('cat/pkg-1'))
		self.assertEqual2(CPV('cat/pkg-0'), CPV('cat/pkg-0'))
		self.assertEqual2(CPV('cat/pkg-1-r1'), CPV('cat/pkg-1-r1'))
		self.assertNotEqual2(CPV('cat/pkg-2-r1'), CPV('cat/pkg-2-r10'))
		self.assertEqual2(CPV('cat/pkg-1_rc2'), CPV('cat/pkg-1_rc2'))
		self.assertNotEqual2(CPV('cat/pkg-2_rc2-r1'), CPV('cat/pkg-2_rc1-r1'))

def test_main():
	test_support.run_unittest(TestGentoolkitCPV)

if __name__ == '__main__':
	test_main()