Пример #1
0
 def test_run_importanize_skip(self, mock_read):
     conf = {
         'exclude': ['*foo.py'],
     }
     self.assertFalse(
         run_importanize('/path/to/importanize/file/foo.py', conf, None))
     self.assertFalse(mock_read.called)
Пример #2
0
 def test_run_importanize_skip(self, mock_read):
     conf = {
         'exclude': ['*foo.py'],
     }
     self.assertFalse(
         run_importanize('/path/to/importanize/file/foo.py', conf, None)
     )
     self.assertFalse(mock_read.called)
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
    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)