def test_find_in_dir(self, mock_glob): mock_glob.return_value = ('pkg-1.ebuild', 'pkg-9999.ebuild') self.assertEqual(list(Ebuild.find_in_directory('some/path')), [ Ebuild('pkg', Version(NumericVersion(1))), Ebuild('pkg', Version(NumericVersion(9999))) ]) self.assertEqual( list(Ebuild.find_in_directory('some/path', exclude_9999=True)), [Ebuild('pkg', Version(NumericVersion(1)))])
def test_parse_parts(self): self.assertEqual(Version.parse_parts(('9999', )), Version(NumericVersion(9999))) self.assertEqual(Version.parse_parts(('1.2.3', )), Version(NumericVersion(1, 2, 3))) self.assertEqual(Version.parse_parts(('4.9', 'r2')), Version(NumericVersion(4, 9), 2)) with self.assertRaises(ValueError): Version.parse_parts('4.9-2') with self.assertRaises(ValueError): Version.parse_parts(('4.9', '2'))
def test_uprev(self): ebuild = Ebuild('mypkg', Version(NumericVersion(1, 2))) self.assertEqual(ebuild.version.revision, 0) ebuild.uprev() self.assertEqual(ebuild.version.revision, 1) ebuild.uprev() self.assertEqual(ebuild.version.revision, 2)
def parse_parts(cls, parts): """Parse an ebuild |Version| from a list of strings. Examples: ('9999',) -> Version(NumericVersion(9999)) ('1.2.3',) -> Version(NumericVersion(1.2.3)) ('4.9', 'r2') -> Version(NumericVersion(4.9, 2)) """ if len(parts) not in (1, 2): raise ValueError('invalid ebuild version format: ' + parts) primary = NumericVersion.parse(parts[0]) # Get the revision if present rev = 0 if len(parts) == 2: rev = cls.parse_revision(parts[1]) return cls(primary, rev)
def test_str(self): self.assertEqual(str(Version(NumericVersion(1, 2), 3)), '1.2-r3') self.assertEqual(str(Version(NumericVersion(1, 2))), '1.2')
def test_is_9999(self): ebuild = Ebuild('mypkg', Version(NumericVersion(9999))) self.assertTrue(ebuild.is_9999()) ebuild = Ebuild('mypkg', Version(NumericVersion(9999), 1)) self.assertFalse(ebuild.is_9999())
def is_9999(self): """Whether the ebuild is a 9999 ebuild.""" version = NumericVersion(9999) return self.version.primary == version and self.revision == 0