def test_main_list(self, mock_print): actual = main( [ six.text_type(self.test_data / "input_few_imports.py"), "--config", six.text_type(self.test_data / "config.json"), "--list", ] ) self.assertEqual(actual, 0) mock_print.assert_has_calls( [ mock.call("stdlib"), mock.call("------"), mock.call("from __future__ import unicode_literals"), mock.call("import datetime as mydatetime"), mock.call(), mock.call("sitepackages"), mock.call("------------"), mock.call("import flake8 as lint"), mock.call(), mock.call("remainder"), mock.call("---------"), mock.call("import z"), mock.call("from a import b"), mock.call("from a.b import d"), mock.call(), mock.call("local"), mock.call("-----"), mock.call("from .module import bar, foo"), ] )
def test_main_version(self, mock_print): self.assertEqual(main(['--version']), 0) self.assertEqual(mock_print.call_count, 1) version = mock_print.mock_calls[0][1][0] self.assertIn('version: {}'.format(__version__), version)
def test_main_version(self, mock_print): self.assertEqual(main(["--version"]), 0) self.assertEqual(mock_print.call_count, 1) version = mock_print.mock_calls[0][1][0] self.assertIn("version: {}".format(__version__), version)
def test_main_list(self, mock_print): actual = main([ six.text_type(self.test_data / 'input_few_imports.py'), '--config', six.text_type(self.test_data / 'config.json'), '--list', ]) self.assertEqual(actual, 0) mock_print.assert_has_calls([ mock.call('stdlib'), mock.call('------'), mock.call('from __future__ import unicode_literals'), mock.call('import datetime as mydatetime'), mock.call(), mock.call('sitepackages'), mock.call('------------'), mock.call('import flake8 as lint'), mock.call(), mock.call('remainder'), mock.call('---------'), mock.call('import z'), mock.call('from a import b'), mock.call('from a.b import d'), mock.call(), mock.call('local'), mock.call('-----'), mock.call('from .module import bar, foo'), ])
def test_main_not_piped_ci(self, mock_print): actual = main([ six.text_type(self.test_data / 'input.py'), '--config', six.text_type(self.test_data / 'config.json'), '--ci', ]) self.assertEqual(actual, 1)
def test_main_not_piped_exception(self, mock_run, mock_print): mock_run.side_effect = ValueError actual = main([ six.text_type(self.test_data / 'input.py'), '--config', six.text_type(self.test_data / 'config.json'), '--ci', ]) self.assertEqual(actual, 1)
def test_main_not_piped(self, mock_print): actual = main([ six.text_type(self.test_data / 'input.py'), '--config', six.text_type(self.test_data / 'config.json'), '--print', '--no-header', ]) self.assertEqual(actual, 0) mock_print.assert_called_once_with(self.output_grouped)
def test_main_not_piped_ci(self, mock_print): actual = main( [ six.text_type(self.test_data / "input.py"), "--config", six.text_type(self.test_data / "config.json"), "--ci", ] ) self.assertEqual(actual, 1)
def test_main_not_piped_exception(self, mock_run, mock_print): mock_run.side_effect = ValueError actual = main( [ six.text_type(self.test_data / "input.py"), "--config", six.text_type(self.test_data / "config.json"), "--ci", ] ) self.assertEqual(actual, 1)
def test_main_not_piped(self, mock_print): actual = main( [ six.text_type(self.test_data / "input.py"), "--config", six.text_type(self.test_data / "config.json"), "--print", "--no-header", ] ) self.assertEqual(actual, 0) mock_print.assert_called_once_with(self.output_grouped)
def test_main_piped(self, mock_stdin, mock_print): mock_stdin.read.return_value = self.input_text actual = main([]) self.assertEqual(actual, 0) mock_print.assert_called_once_with(self.output_grouped)
def test_main_piped(self, mock_stdin, mock_print): mock_stdin.read.return_value = self.input_text actual = main(["--length", "80"]) self.assertEqual(actual, 0) mock_print.assert_called_once_with(self.output_grouped)
def test_main_python_version(self): self.assertEqual( main(["--py={}".format(3 - sys.version_info.major % 2)]), 0 )