예제 #1
0
    def test_it_opens_custom_file(self):
        with NamedTemporaryFile() as temp_file:
            main(['-i', temp_file.name])
            file_object = self._mock_stream_to_regexp.call_args[0][0]

            self.assertIsInstance(file_object, TextIOWrapper)
            self.assertEqual(temp_file.name, file_object.name)
예제 #2
0
    def test_it_refuses_unknown_formatters(self):
        with patch('sys.stderr', new_callable=StringIO):
            with self.assertRaises(SystemExit) as exception_context:
                main(['-f', 'sjaflksag'])

        self.assertNotEqual(0, exception_context.exception.code)
        self._mock_stream_to_regexp.assert_not_called()
예제 #3
0
    def test_it_can_print_help(self, mock_stdout):
        with self.assertRaises(SystemExit) as exception_context:
            main(['-h'])

        self.assertEqual(0, exception_context.exception.code)
        self.assertIn("Words to Regular Expression", mock_stdout.getvalue())
        self._mock_stream_to_regexp.assert_not_called()
예제 #4
0
    def test_it_prints_out_version(self):
        with patch('sys.stdout', new_callable=StringIO) as mock_stdout:
            main(['--version'])

        output = mock_stdout.getvalue()

        self.assertIn(VERSION, output)
        self.assertIn(APPLICATION_NAME, output)
        self.assertIn(CHANGELOG_URL, output)
예제 #5
0
    def test_it_converts_stream_to_regular_expression(self, mock_stdout):
        with NamedTemporaryFile() as temp_file:
            main(['-i', temp_file.name])

        self.assertEqual(PythonFormatter._EMPTY_STRING_MATCH, mock_stdout.getvalue())
예제 #6
0
 def test_it_uses_stdin_as_input_by_default(self):
     main([])
     self._mock_stream_to_regexp.called_with([sys.stdin, ANY])
예제 #7
0
 def test_it_accepts_valid_formatters(self):
     for formatter_class in ALL_FORMATTERS:
         formatter_code = formatter_class.code()
         main(['-f', formatter_code])
         self._mock_stream_to_regexp.called_with([ANY, formatter_class])
         self._mock_stream_to_regexp.reset()
예제 #8
0
 def test_it_uses_python_formatter_by_default(self):
     main([])
     self._mock_stream_to_regexp.called_with([ANY, PythonFormatter])