示例#1
0
class TestCLI(testtools.TestCase):
    def setUp(self):
        super(TestCLI, self).setUp()
        self._cli = CLI()

    def test_cli_raises_usage_without_arguments(self):
        self.assertRaises(DocoptExit, lambda: self._cli.main())

    def test_cli_prints_version(self):
        with patch('sys.argv', ['bin/molecule', '--version']):
            with patch('sys.stdout', StringIO.StringIO()) as mocked_stdout:
                result = self.assertRaises(SystemExit, lambda: self._cli.main())
                stdout = mocked_stdout.getvalue().strip()

                self.assertEqual(result.code, 0)
                self.assertThat(stdout, MatchesRegex('^\d\.\d\.\d'))

    def test_cli_raises_usage_with_invalid_sub_command(self):
        with patch('sys.argv', ['bin/molecule', 'invalid-subcommand']):
            self.assertRaises(DocoptExit, lambda: self._cli.main())
示例#2
0
 def setUp(self):
     super(TestCLI, self).setUp()
     self._cli = CLI()