def test_should_call_command(self): self.popen_mock.communicate() self.popen_mock.poll().AndReturn(0) self.mox.ReplayAll() core.execute_virtualenv_command(self.vip_dir, "command", ["-arg", "123"]) self.mox.VerifyAll()
def test_should_raise_VipError_when_CalledProcessError_is_found(self): (self.popen_mock.communicate() .AndRaise(subprocess.CalledProcessError(1, "error"))) self.popen_mock.poll().AndReturn(127) self.mox.ReplayAll() with self.assertRaises(core.VipError): core.execute_virtualenv_command(self.vip_dir, "command", ["-arg", "123"]) self.mox.VerifyAll()
def main(): parser, args = create_argument_parser() commands = ["init", "locate", "command"] # Configure logger using --verbose option core.logger.verbose = bool(args.verbose) with protect_from_VipError(): if args.version: sys.stdout.write("%s\n" % vip.VERSION) sys.exit(0) # Check for only one command used_commands = [int(bool(getattr(args, cmd))) for cmd in commands] if sum(used_commands) > 1: parser.print_help() elif args.init: directory = core.create_virtualenv(args.init) core.logger.info("Initialized virtualenv in %s" % directory) elif args.locate: sys.stdout.write(core.find_vip_directory(args.locate) + "\n") elif args.command: directory = core.find_vip_directory() return_code = core.execute_virtualenv_command( directory, args.command, args.arguments) sys.exit(return_code) else: parser.print_help()
def test_should_propagate_SIGINT(self): self.popen_mock.communicate().AndRaise(KeyboardInterrupt()) self.popen_mock.poll().AndReturn(None) self.popen_mock.terminate() self.mox.ReplayAll() code = core.execute_virtualenv_command(self.vip_dir, 'command', ["-arg", "123"]) self.mox.VerifyAll()
def test_create_virtualenv(self): repo_dir = path.normpath(path.join(path.dirname(__file__), 'fixtures', 'test1')) vip_dir = path.join(repo_dir, '.vip') self.mox.StubOutWithMock(virtualenv, 'create_environment') self.mox.StubOutWithMock(core, 'execute_virtualenv_command') core.execute_virtualenv_command( vip_dir, 'pip', ['install', '-r', path.join(repo_dir, 'requirements.txt')]) self.mox.ReplayAll() self.mox.StubOutWithMock(core, 'logger', use_mock_anything=True) dir_ = core.create_virtualenv(repo_dir) mox.Reset(core.logger) self.mox.VerifyAll() self.assertEqual(vip_dir, dir_)
def test_should_propagate_status_code(self): self.popen_mock.communicate() self.popen_mock.poll().AndReturn(123) self.popen_mock.returncode = 123 self.mox.ReplayAll() code = core.execute_virtualenv_command(self.vip_dir, 'command', ["-arg", "123"]) self.mox.VerifyAll() self.assertEqual(123, code)
def test_should_raise_VipError_when_command_is_not_found(self): missing = path.sep.join(["missing", ".vip"]) with self.assertRaisesRegexp(core.VipError, "not found"): core.execute_virtualenv_command(missing, "command", [])