Beispiel #1
0
def test_find_sql_in_directory(test_data):
    args = "%s -r --types sql" % test_data.get_path("test_00")
    args = args.split()

    with patch("format_sql.main.handle_sql_file") as mocked_handle_sql_file, patch(
        "format_sql.main._write_back"
    ) as mocked_write_back:

        main(args)

        assert mocked_handle_sql_file.call_count == 3
        arguments = sorted(
            [
                mocked_handle_sql_file.call_args_list[0][0][0],
                mocked_handle_sql_file.call_args_list[1][0][0],
                mocked_handle_sql_file.call_args_list[2][0][0],
            ]
        )

        assert mocked_write_back.call_count == 3

    expected_paths = ["one.sql", "two.sql", "sub_dir/four.sql"]

    for path, expected in zip_longest(arguments, sorted(expected_paths)):
        assert path.endswith("format-sql/tests/data/test_00/%s" % expected)
Beispiel #2
0
def test_dry_run(test_data):
    expected_content = test_data.get_content("test_04/after.py")
    args = "%s --dry-run" % test_data.get_path("test_04/before.py")

    with patch("format_sql.main.print_data") as mocked_print_data:
        main(args.split())

        assert mocked_print_data.call_args_list == [call(expected_content)]
Beispiel #3
0
def test_dry_run(test_data):
    expected_content = test_data.get_content('test_04/after.py')
    args = '%s --dry-run' % test_data.get_path('test_04/before.py')

    with patch('format_sql.main.print_data') as mocked_print_data:
        main(args.split())

        assert mocked_print_data.call_args_list == [call(expected_content)]
Beispiel #4
0
def test_find_py_in_directory(test_data):
    args = '%s -r --types py' % test_data.get_path('test_00')
    args = args.split()

    with patch('format_sql.main.handle_py_file') as mocked_handle_py_file, \
            patch('format_sql.main._write_back') as mocked_write_back:

        main(args)

        assert mocked_handle_py_file.call_count == 2
        arguments = sorted([
            mocked_handle_py_file.call_args_list[0][0][0],
            mocked_handle_py_file.call_args_list[1][0][0],
        ])

        assert mocked_write_back.call_count == 2

    expected_paths = ['three.py', 'sub_dir/five.py']

    for path, expected in zip_longest(arguments, sorted(expected_paths)):
        assert path.endswith('format-sql/tests/data/test_00/%s' % expected)