Esempio n. 1
0
class MambaAdminPackagePackTest(unittest.TestCase):

    def setUp(self):
        self.config = PackagePackOptions()
        self.stdout = sys.stdout
        self.capture = StringIO()
        sys.stdout = self.capture

    def tearDown(self):
        sys.stdout = self.stdout

    def test_wrong_number_of_args(self):
        self.assertRaises(
            usage.UsageError, self.config.parseOptions, ['wrong', 'fail']
        )

    def test_use_outside_application_directory_fails(self):
        _test_use_outside_application_directory_fails(self)

    def test_egg_option(self):

        with fake_project():
            self.config.parseOptions(['-e'])
            self.assertEqual(self.config['egg'], True)

    def test_no_egg_options(self):

        with fake_project():
            self.config.parseOptions()
            self.assertEqual(self.config['egg'], False)

    def test_cfgdir_options(self):

        with fake_project():
            self.config.parseOptions(['-c'])
            self.assertEqual(self.config['cfgdir'], True)

    def test_no_cfgdir_options(self):

        with fake_project():
            self.config.parseOptions()
            self.assertEqual(self.config['cfgdir'], False)

    def test_invalid_JSON_entry_point(self):

        with fake_project():
            self.assertRaises(
                usage.UsageError,
                self.config.parseOptions, ['--entry_point=""']
            )

    def test_entry_point_not_a_dict(self):

        with fake_project():
            self.assertRaises(
                usage.UsageError,
                self.config.parseOptions, ['--entry_points=["fail"]']
            )

    def test_invalid_JSON_extra_directories(self):

        with fake_project():
            self.assertRaises(
                usage.UsageError,
                self.config.parseOptions, ['--extra_directories=fail']
            )

    def test_entry_point_not_a_list(self):

        with fake_project():
            self.assertRaises(
                usage.UsageError,
                self.config.parseOptions, ['--extra_directories="fail"']
            )

    def test_not_valid_rfc2822_email(self):

        with fake_project():
            sys.exit = lambda x: None
            self.config.parseOptions(['--email=no@valid'])
            self.assertEqual(
                self.capture.getvalue(),
                'error: the given email address no@valid is not a valid '
                'RFC2822 email address, check http://www.rfc-editor.org/'
                'rfc/rfc2822.txt for very extended details\n'
            )

    def test_when_no_author_get_user_executing(self):

        with fake_project():
            self.config.parseOptions()
            self.assertEqual(self.config['author'], getpass.getuser())

    def test_default_email(self):

        with fake_project():
            self.config.parseOptions()
            self.assertEqual(
                self.config['email'],
                '{}@localhost'.format(getpass.getuser())
            )
Esempio n. 2
0
 def setUp(self):
     self.config = PackagePackOptions()
     self.stdout = sys.stdout
     self.capture = StringIO()
     sys.stdout = self.capture
Esempio n. 3
0
class PackagePackerTest(unittest.TestCase):

    def setUp(self):
        self.packer = Packer()
        self.config = PackagePackOptions()

    def tearDown(self):
        with fake_project():
            self.packer.do(['rm', 'README.rst'])
            self.packer.do(['rm', 'LICENSE'])
            self.packer.do(['rmdir', 'docs'])

    def test_do(self):
        self.packer.do(['touch', 'test_file.tmp'])
        self.assertTrue(os.path.exists('test_file.tmp'))
        self.packer.do(['rm', 'test_file.tmp'])
        self.assertFalse(os.path.exists('test_file.tmp'))

    def test_pack_fails_on_no_README_or_no_LICENSE(self):

        with fake_project():
            self.config.parseOptions()
            self.assertRaises(
                usage.UsageError,
                self.packer.pack_application,
                'sdist', self.config,
                config.Application('config/application.json')
            )

    def test_pack_fails_on_no_docs_directory(self):

        with self._generate_README_and_LICENSE():
            self.config.parseOptions()
            self.assertRaises(
                usage.UsageError,
                self.packer.pack_application,
                'sdist', self.config,
                config.Application('config/application.json')
            )
            self.assertTrue(os.path.exists('README.rst'))
            self.assertTrue(os.path.exists('LICENSE'))
            self.assertFalse(os.path.exists('docs'))

    @defer.inlineCallbacks
    def test_pack_sdist(self):

        result = yield utils.getProcessValue('mamba-admin', [], os.environ)
        if result == 1:
            raise unittest.SkipTest('mamba framework is not installed yet')

        with self._generate_docs():
            self.config.parseOptions()
            self.config['name'] = 'mamba-dummy'
            self.packer.pack_application(
                'sdist', self.config,
                config.Application('config/application.json')
            )
            self.assertTrue(os.path.exists('mamba-dummy-0.1.2.tar.gz'))
            self.packer.do(['rm', 'mamba-dummy-0.1.2.tar.gz'])

    @defer.inlineCallbacks
    def test_pack_egg(self):

        result = yield utils.getProcessValue('mamba-admin', [], os.environ)
        if result == 1:
            raise unittest.SkipTest('mamba framework is not installed yet')

        with self._generate_docs():
            self.config.parseOptions()
            self.config['name'] = 'mamba-dummy'
            self.packer.pack_application(
                'bdist_egg', self.config,
                config.Application('config/application.json')
            )
            major, minor = sys.version_info[:2]
            self.assertTrue(os.path.exists(
                'mamba_dummy-0.1.2-py{}.{}.egg'.format(major, minor))
            )
            self.packer.do(
                ['rm', 'mamba_dummy-0.1.2-py{}.{}.egg'.format(major, minor)]
            )

    @defer.inlineCallbacks
    def test_is_mamba_package_for_egg_file(self):

        result = yield utils.getProcessValue('mamba-admin', [], os.environ)
        if result == 1:
            raise unittest.SkipTest('mamba framework is not installed yet')

        with self._generate_docs():
            self.config.parseOptions()
            self.config['name'] = 'mamba-dummy'
            self.packer.pack_application(
                'bdist_egg', self.config,
                config.Application('config/application.json')
            )
            major, minor = sys.version_info[:2]
            self.assertTrue(os.path.exists(
                'mamba_dummy-0.1.2-py{}.{}.egg'.format(major, minor))
            )
            path = filepath.FilePath(
                'mamba_dummy-0.1.2-py{}.{}.egg'.format(major, minor)
            )
            is_mamba_package = self.packer.is_mamba_package(path)
            self.assertTrue(is_mamba_package)
            self.packer.do(
                ['rm', 'mamba_dummy-0.1.2-py{}.{}.egg'.format(major, minor)]
            )

    @defer.inlineCallbacks
    def test_is_mamba_package_for_tar_file(self):

        result = yield utils.getProcessValue('mamba-admin', [], os.environ)
        if result == 1:
            raise unittest.SkipTest('mamba framework is not installed yet')

        with self._generate_docs():
            self.config.parseOptions()
            self.config['name'] = 'mamba-dummy'
            self.packer.pack_application(
                'sdist', self.config,
                config.Application('config/application.json')
            )
            self.assertTrue(os.path.exists('mamba-dummy-0.1.2.tar.gz'))
            path = filepath.FilePath('mamba-dummy-0.1.2.tar.gz')
            is_mamba_package = self.packer.is_mamba_package(path)
            self.assertTrue(is_mamba_package)
            self.packer.do(['rm', 'mamba-dummy-0.1.2.tar.gz'])

    @contextmanager
    def _generate_README_and_LICENSE(self):

        with fake_project():
            self.packer.do(['touch', 'README.rst'])
            self.packer.do(['touch', 'LICENSE'])
            yield
            self.packer.do(['rm', 'README.rst', 'LICENSE'])

    @contextmanager
    def _generate_docs(self):

        if skip_command_line_tests is True:
            raise unittest.SkipTest('skip_command_line_tests is set as True')

        with self._generate_README_and_LICENSE():
            self.packer.do(['mkdir', 'docs'])
            yield
            self.packer.do(['rmdir', 'docs'])
Esempio n. 4
0
 def setUp(self):
     self.packer = Packer()
     self.config = PackagePackOptions()
Esempio n. 5
0
 def setUp(self):
     self.config = PackagePackOptions()
     self.stdout = sys.stdout
     self.capture = StringIO()
     sys.stdout = self.capture
Esempio n. 6
0
class MambaAdminPackagePackTest(unittest.TestCase):

    def setUp(self):
        self.config = PackagePackOptions()
        self.stdout = sys.stdout
        self.capture = StringIO()
        sys.stdout = self.capture

    def tearDown(self):
        sys.stdout = self.stdout

    def test_wrong_number_of_args(self):
        self.assertRaises(
            usage.UsageError, self.config.parseOptions, ['wrong', 'fail']
        )

    def test_use_outside_application_directory_fails(self):
        _test_use_outside_application_directory_fails(self)

    def test_egg_option(self):

        with fake_project():
            self.config.parseOptions(['-e'])
            self.assertEqual(self.config['egg'], True)

    def test_no_egg_options(self):

        with fake_project():
            self.config.parseOptions()
            self.assertEqual(self.config['egg'], False)

    def test_cfgdir_options(self):

        with fake_project():
            self.config.parseOptions(['-c'])
            self.assertEqual(self.config['cfgdir'], True)

    def test_no_cfgdir_options(self):

        with fake_project():
            self.config.parseOptions()
            self.assertEqual(self.config['cfgdir'], False)

    def test_invalid_JSON_entry_point(self):

        with fake_project():
            self.assertRaises(
                usage.UsageError,
                self.config.parseOptions, ['--entry_point=""']
            )

    def test_entry_point_not_a_dict(self):

        with fake_project():
            self.assertRaises(
                usage.UsageError,
                self.config.parseOptions, ['--entry_points=["fail"]']
            )

    def test_invalid_JSON_extra_directories(self):

        with fake_project():
            self.assertRaises(
                usage.UsageError,
                self.config.parseOptions, ['--extra_directories=fail']
            )

    def test_entry_point_not_a_list(self):

        with fake_project():
            self.assertRaises(
                usage.UsageError,
                self.config.parseOptions, ['--extra_directories="fail"']
            )

    def test_not_valid_rfc2822_email(self):

        with fake_project():
            sys.exit = lambda x: None
            self.config.parseOptions(['--email=no@valid'])
            self.assertEqual(
                self.capture.getvalue(),
                'error: the given email address no@valid is not a valid '
                'RFC2822 email address, check http://www.rfc-editor.org/'
                'rfc/rfc2822.txt for very extended details\n'
            )

    def test_when_no_author_get_user_executing(self):

        with fake_project():
            self.config.parseOptions()
            self.assertEqual(self.config['author'], getpass.getuser())

    def test_default_email(self):

        with fake_project():
            self.config.parseOptions()
            self.assertEqual(
                self.config['email'],
                '{}@localhost'.format(getpass.getuser())
            )
Esempio n. 7
0
 def setUp(self):
     self.packer = Packer()
     self.config = PackagePackOptions()
Esempio n. 8
0
class PackagePackerTest(unittest.TestCase):

    def setUp(self):
        self.packer = Packer()
        self.config = PackagePackOptions()

    def tearDown(self):
        with fake_project():
            self.packer.do(['rm', 'README.rst'])
            self.packer.do(['rm', 'LICENSE'])
            self.packer.do(['rmdir', 'docs'])

    def test_do(self):
        self.packer.do(['touch', 'test_file.tmp'])
        self.assertTrue(os.path.exists('test_file.tmp'))
        self.packer.do(['rm', 'test_file.tmp'])
        self.assertFalse(os.path.exists('test_file.tmp'))

    def test_pack_fails_on_no_README_or_no_LICENSE(self):

        with fake_project():
            self.config.parseOptions()
            self.assertRaises(
                usage.UsageError,
                self.packer.pack_application,
                'sdist', self.config,
                config.Application('config/application.json')
            )

    def test_pack_fails_on_no_docs_directory(self):

        with self._generate_README_and_LICENSE():
            self.config.parseOptions()
            self.assertRaises(
                usage.UsageError,
                self.packer.pack_application,
                'sdist', self.config,
                config.Application('config/application.json')
            )
            self.assertTrue(os.path.exists('README.rst'))
            self.assertTrue(os.path.exists('LICENSE'))
            self.assertFalse(os.path.exists('docs'))

    @defer.inlineCallbacks
    def test_pack_sdist(self):

        result = yield utils.getProcessValue('mamba-admin', [], os.environ)
        if result == 1:
            raise unittest.SkipTest('mamba framework is not installed yet')

        with self._generate_docs():
            self.config.parseOptions()
            self.config['name'] = 'mamba-dummy'
            self.packer.pack_application(
                'sdist', self.config,
                config.Application('config/application.json')
            )
            self.assertTrue(os.path.exists('mamba-dummy-0.1.2.tar.gz'))
            self.packer.do(['rm', 'mamba-dummy-0.1.2.tar.gz'])

    @defer.inlineCallbacks
    def test_pack_egg(self):

        result = yield utils.getProcessValue('mamba-admin', [], os.environ)
        if result == 1:
            raise unittest.SkipTest('mamba framework is not installed yet')

        with self._generate_docs():
            self.config.parseOptions()
            self.config['name'] = 'mamba-dummy'
            self.packer.pack_application(
                'bdist_egg', self.config,
                config.Application('config/application.json')
            )
            major, minor = sys.version_info[:2]
            self.assertTrue(os.path.exists(
                'mamba_dummy-0.1.2-py{}.{}.egg'.format(major, minor))
            )
            self.packer.do(
                ['rm', 'mamba_dummy-0.1.2-py{}.{}.egg'.format(major, minor)]
            )

    def test_is_mamba_package_for_tar_file(self):

        pass

    @contextmanager
    def _generate_README_and_LICENSE(self):

        with fake_project():
            self.packer.do(['touch', 'README.rst'])
            self.packer.do(['touch', 'LICENSE'])
            yield
            self.packer.do(['rm', 'README.rst', 'LICENSE'])

    @contextmanager
    def _generate_docs(self):

        if skip_command_line_tests is True:
            raise unittest.SkipTest('skip_command_line_tests is set as True')

        with self._generate_README_and_LICENSE():
            self.packer.do(['mkdir', 'docs'])
            yield
            self.packer.do(['rmdir', 'docs'])
Esempio n. 9
0
class PackagePackerTest(unittest.TestCase):

    def setUp(self):
        self.packer = Packer()
        self.config = PackagePackOptions()

    def tearDown(self):
        with fake_project():
            self.packer.do(['rm', 'README.rst'])
            self.packer.do(['rm', 'LICENSE'])
            self.packer.do(['rmdir', 'docs'])

    def test_do(self):
        self.packer.do(['touch', 'test_file.tmp'])
        self.assertTrue(os.path.exists('test_file.tmp'))
        self.packer.do(['rm', 'test_file.tmp'])
        self.assertFalse(os.path.exists('test_file.tmp'))

    def test_pack_fails_on_no_README_or_no_LICENSE(self):

        with fake_project():
            self.config.parseOptions()
            self.assertRaises(
                usage.UsageError,
                self.packer.pack_application,
                'sdist', self.config,
                config.Application('config/application.json')
            )

    def test_pack_fails_on_no_docs_directory(self):

        with self._generate_README_and_LICENSE():
            self.config.parseOptions()
            self.assertRaises(
                usage.UsageError,
                self.packer.pack_application,
                'sdist', self.config,
                config.Application('config/application.json')
            )
            self.assertTrue(os.path.exists('README.rst'))
            self.assertTrue(os.path.exists('LICENSE'))
            self.assertFalse(os.path.exists('docs'))

    def test_pack_sdist(self):

        with self._generate_docs():
            self.config.parseOptions()
            self.config['name'] = 'mamba-dummy'
            self.packer.pack_application(
                'sdist', self.config,
                config.Application('config/application.json')
            )
            self.assertTrue(os.path.exists('mamba-dummy-0.1.2.tar.gz'))
            self.packer.do(['rm', 'mamba-dummy-0.1.2.tar.gz'])

    def test_pack_egg(self):

        with self._generate_docs():
            self.config.parseOptions()
            self.config['name'] = 'mamba-dummy'
            self.packer.pack_application(
                'bdist_egg', self.config,
                config.Application('config/application.json')
            )
            major, minor = sys.version_info[:2]
            self.assertTrue(os.path.exists(
                'mamba_dummy-0.1.2-py{}.{}.egg'.format(major, minor))
            )
            self.packer.do(
                ['rm', 'mamba_dummy-0.1.2-py{}.{}.egg'.format(major, minor)]
            )

    def test_is_mamba_package_for_tar_file(self):

        pass

    @contextmanager
    def _generate_README_and_LICENSE(self):

        with fake_project():
            self.packer.do(['touch', 'README.rst'])
            self.packer.do(['touch', 'LICENSE'])
            yield
            self.packer.do(['rm', 'README.rst', 'LICENSE'])

    @contextmanager
    def _generate_docs(self):

        if skip_command_line_tests is True:
            raise unittest.SkipTest('skip_command_line_tests is set as True')

        with self._generate_README_and_LICENSE():
            self.packer.do(['mkdir', 'docs'])
            yield
            self.packer.do(['rmdir', 'docs'])