def setUp(self): self.config = PackageInstallOptions() self.capture = StringIO() self.stdout = sys.stdout sys.stdout = self.capture
class MambaAdminPackageInstallTest(unittest.TestCase): def setUp(self): self.config = PackageInstallOptions() self.capture = StringIO() self.stdout = sys.stdout 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, [ '-u', 'test', 'wrong', 'fail'] ) def test_use_outside_application_directory_fails(self): _test_use_outside_application_directory_fails(self) def test_user_and_global_cant_be_together(self): with fake_project(): self.assertRaises( usage.UsageError, self.config.parseOptions, ['-u', '-g'] ) def test_invalid_JSON_entry_point(self): with fake_project(): self.assertRaises( usage.UsageError, self.config.parseOptions, ['-u', '--entry_point=""'] ) def test_entry_point_not_a_dict(self): with fake_project(): self.assertRaises( usage.UsageError, self.config.parseOptions, ['-u', '--entry_points=["fail"]'] ) def test_invalid_JSON_extra_directories(self): with fake_project(): self.assertRaises( usage.UsageError, self.config.parseOptions, ['-u', '--extra_directories=fail'] ) def test_entry_point_not_a_list(self): with fake_project(): self.assertRaises( usage.UsageError, self.config.parseOptions, ['-u', '--extra_directories="fail"'] ) def test_not_valid_rfc2822_email(self): with fake_project(): sys.exit = lambda x: None self.config.parseOptions(['-u', '--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(['-u']) self.assertEqual(self.config['author'], getpass.getuser()) def test_default_email(self): with fake_project(): self.config.parseOptions(['-u']) self.assertEqual( self.config['email'], '{}@localhost'.format(getpass.getuser()) ) def test_default_name(self): with fake_project(): self.config.parseOptions(['-u']) self.assertEqual(self.config['name'], 'mamba-dummy') def test_custom_name(self): with fake_project(): self.config.parseOptions(['-u', 'test-name']) self.assertEqual(self.config['name'], 'test-name')