def test_run_importanize_print(self, mock_print): test_file = os.path.join(os.path.dirname(__file__), 'test_data', 'input.txt') expected_file = os.path.join(os.path.dirname(__file__), 'test_data', 'output_grouped.txt') expected = (read(expected_file) if six.PY3 else read(expected_file).encode('utf-8')) self.assertTrue( run_importanize(test_file, PEP8_CONFIG, mock.MagicMock(print=True, formatter='grouped'))) mock_print.assert_called_once_with(expected)
def test_run_importanize_print_inline_group_formatter(self, mock_print): test_file = os.path.join(os.path.dirname(__file__), 'test_data', 'input.txt') expected_file = os.path.join(os.path.dirname(__file__), 'test_data', 'output_inline_grouped.txt') expected = ( read(expected_file) if six.PY3 else read(expected_file).encode('utf-8') ) self.assertTrue( run_importanize( test_file, PEP8_CONFIG, mock.MagicMock(print=True, formatter='inline-grouped')) ) mock_print.assert_called_once_with(expected)
def test_run_importanize_write(self, mock_open): test_file = os.path.join(os.path.dirname(__file__), 'test_data', 'input.txt') expected_file = os.path.join(os.path.dirname(__file__), 'test_data', 'output_grouped.txt') expected = read(expected_file).encode('utf-8') self.assertTrue( run_importanize(test_file, PEP8_CONFIG, mock.MagicMock(print=False, formatter='grouped'))) mock_open.assert_called_once_with(test_file, 'wb') mock_open.return_value \ .__enter__.return_value \ .write.assert_called_once_with(expected)
def test_read(self, mock_open): actual = read(mock.sentinel.path) mock_open.assert_called_once_with(mock.sentinel.path, "rb") mock_open.return_value.__enter__.return_value.read.assert_called_once_with() mock_open.return_value.__enter__.return_value.read.return_value.decode.assert_called_once_with( "utf-8" ) self.assertEqual( actual, ( mock_open.return_value.__enter__.return_value.read.return_value.decode.return_value ), )
def test_run_importanize_write_inline_group_formatter(self, mock_open): test_file = os.path.join(os.path.dirname(__file__), 'test_data', 'input.txt') expected_file = os.path.join(os.path.dirname(__file__), 'test_data', 'output_inline_grouped.txt') expected = read(expected_file).encode('utf-8') self.assertTrue( run_importanize( test_file, PEP8_CONFIG, mock.MagicMock(print=False, formatter='inline-grouped')) ) mock_open.assert_called_once_with(test_file, 'wb') mock_open.return_value \ .__enter__.return_value \ .write.assert_called_once_with(expected)