Beispiel #1
0
 def test_invalid_package_exception(self):
     try:
         raise InvalidPackage('foo')
     except InvalidPackage as e:
         self.assertEqual('foo', str(e))
         self.assertEqual(None, e.package_path)
     try:
         raise InvalidPackage('foo', package_path='./bar')
     except InvalidPackage as e:
         self.assertEqual("Error(s) in package './bar':\nfoo", str(e))
         self.assertEqual('./bar', e.package_path)
Beispiel #2
0
 def _get_package(self, pkg_name):
     if pkg_name not in self._packages:
         pkg_xml = self._release_instance.get_package_xml(pkg_name)
         try:
             pkg = parse_package_string(pkg_xml)
         except InvalidPackage as e:
             raise InvalidPackage(pkg_name + ': %s' % str(e))
         self._packages[pkg_name] = pkg
     return self._packages[pkg_name]
 def _get_package(self, pkg_name):
     if pkg_name not in self._packages:
         repo = self._distribution_instance.repositories[
             self._distribution_instance.source_packages[pkg_name].
             repository_name].source_repository
         assert repo is not None, "Package '%s' in repository '%s' is missing a source entry." % (
             pkg_name, repo.name)
         pkg_xml = self._distribution_instance.get_source_package_xml(
             pkg_name)
         try:
             pkg = parse_package_string(pkg_xml)
         except InvalidPackage as e:
             raise InvalidPackage(pkg_name + ': %s' % str(e))
         self._packages[pkg_name] = pkg
     return self._packages[pkg_name]
    def test_validate_package(self):
        maint = self.get_maintainer()
        pack = Package('foo',
                       name='bar_2go',
                       package_format='1',
                       version='0.0.0',
                       version_abi='pabi',
                       description='pdesc',
                       licenses=['BSD'],
                       maintainers=[maint])
        pack.validate()
        # check invalid names
        pack.name = '2bar'
        pack.validate()
        pack.name = 'bar bza'
        self.assertRaises(InvalidPackage, Package.validate, pack)
        pack.name = 'bar-bza'
        # valid for now because for backward compatibility only
        #self.assertRaises(InvalidPackage, Package.validate, pack)
        pack.name = 'BAR'
        pack.validate()
        # check authors emails
        pack.name = 'bar'
        auth1 = Mock()
        auth2 = Mock()
        auth2.validate.side_effect = InvalidPackage('foo')
        pack.authors = [auth1, auth2]
        self.assertRaises(InvalidPackage, Package.validate, pack)
        pack.authors = []
        pack.validate()
        # check maintainer required with email
        pack.maintainers = []
        self.assertRaises(InvalidPackage, Package.validate, pack)
        pack.maintainers = [maint]
        maint.email = None
        self.assertRaises(InvalidPackage, Package.validate, pack)
        maint.email = '*****@*****.**'

        for dep_type in [
                pack.build_depends, pack.buildtool_depends,
                pack.build_export_depends, pack.buildtool_export_depends,
                pack.exec_depends, pack.test_depends, pack.doc_depends
        ]:
            pack.validate()
            depend = Dependency(pack.name)
            dep_type.append(depend)
            self.assertRaises(InvalidPackage, Package.validate, pack)
            dep_type.remove(depend)
 def _get_package(self, pkg_name):
     if pkg_name not in self._packages:
         repo = self._distribution_instance.repositories[
             self._distribution_instance.release_packages[pkg_name].
             repository_name].release_repository
         assert repo is not None and repo.version is not None, "Package '%s' in repository '%s' has no version set" % (
             pkg_name, repo.name)
         assert 'release' in repo.tags, "Package '%s' in repository '%s' has no 'release' tag set" % (
             pkg_name, repo.name)
         pkg_xml = self._distribution_instance.get_release_package_xml(
             pkg_name)
         try:
             pkg = parse_package_string(pkg_xml)
         except InvalidPackage as e:
             raise InvalidPackage(pkg_name + ': %s' % str(e))
         self._packages[pkg_name] = pkg
     return self._packages[pkg_name]
Beispiel #6
0
    def test_validate_package(self):
        maint = self.get_maintainer()
        pack = Package('foo',
                       name='bar_2go',
                       package_format='1',
                       version='0.0.1',
                       description='pdesc',
                       licenses=['BSD'],
                       maintainers=[maint])
        pack.validate()

        # names that should error
        pack.name = 'bar bza'
        self.assertRaises(InvalidPackage, Package.validate, pack)
        pack.name = 'foo%'
        self.assertRaises(InvalidPackage, Package.validate, pack)

        # names that should throw warnings
        pack.name = '2bar'
        warnings = []
        pack.validate(warnings=warnings)
        self.assertIn('naming conventions', warnings[0])

        pack.name = 'bar-bza'
        warnings = []
        pack.validate(warnings=warnings)
        self.assertEquals(warnings, [])

        pack.name = 'BAR'
        warnings = []
        pack.validate(warnings=warnings)
        self.assertIn('naming conventions', warnings[0])

        # dashes are permitted for a non-catkin package
        pack.exports.append(Export('build_type', 'other'))
        pack.name = 'bar-bza'
        warnings = []
        pack.validate(warnings=warnings)
        self.assertEquals(warnings, [])
        pack.exports.pop()

        # check authors emails
        pack.name = 'bar'
        auth1 = Mock()
        auth2 = Mock()
        auth2.validate.side_effect = InvalidPackage('foo')
        pack.authors = [auth1, auth2]
        self.assertRaises(InvalidPackage, Package.validate, pack)
        pack.authors = []
        pack.validate()

        # check maintainer required with email
        pack.maintainers = []
        self.assertRaises(InvalidPackage, Package.validate, pack)
        pack.maintainers = [maint]
        maint.email = None
        self.assertRaises(InvalidPackage, Package.validate, pack)
        maint.email = '*****@*****.**'

        for dep_type in [
                pack.build_depends, pack.buildtool_depends,
                pack.build_export_depends, pack.buildtool_export_depends,
                pack.exec_depends, pack.test_depends, pack.doc_depends
        ]:
            pack.validate()
            depend = Dependency(pack.name)
            dep_type.append(depend)
            self.assertRaises(InvalidPackage, Package.validate, pack)
            dep_type.remove(depend)