Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix writing multiple input files to single output file #58

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/com2ann.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,8 @@ def main() -> None:
options = Options(**args)

for infile in infiles:
outfile = outfile or infile
process_single_entry(in_path=infile, out_path=outfile, options=options)
cur_outfile = outfile or infile
process_single_entry(in_path=infile, out_path=cur_outfile, options=options)


if __name__ == '__main__':
Expand Down
40 changes: 40 additions & 0 deletions src/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import pathlib
from dataclasses import asdict
from typing import Any, Callable, Iterable, TypedDict

import pytest
Expand Down Expand Up @@ -216,3 +217,42 @@ def test_process_single_entry__dir(
options=options,
),
]


@pytest.fixture
def parse_cli_args(
test_path: pathlib.Path,
mocker: Any,
options: com2ann.Options,
) -> Any:
f1 = test_path / "f1.py"
f2 = test_path / "f2.py"

f1.write_text("f1 = True")
f2.write_text("f2 = False")

args = {'infiles': [f1, f2], 'outfile': None, **asdict(options)}
return mocker.patch("com2ann.parse_cli_args", return_value=args)


def test_process_multiple_input_files(
test_path: pathlib.Path, translate_file: Any,
mocker: Any, parse_cli_args: Any,
options: com2ann.Options
) -> None:
com2ann.main()

assert translate_file.mock_calls == [
mocker.call(
infile=str(test_path / "f1.py"),
outfile=str(test_path / "f1.py"),
options=options,
),
mocker.call(
infile=str(test_path / "f2.py"),
outfile=str(test_path / "f2.py"),
options=options,
),
]
assert (test_path / "f1.py").read_text() == "f1 = True"
assert (test_path / "f2.py").read_text() == "f2 = False"