Skip to content

Commit

Permalink
Change: Ensure that some.file is removed after the test run
Browse files Browse the repository at this point in the history
Improve test by creating the test file in a temporary directory that
gets removed after the test finishes.
  • Loading branch information
bjoernricks committed Apr 14, 2023
1 parent 668bc9a commit e282290
Showing 1 changed file with 39 additions and 33 deletions.
72 changes: 39 additions & 33 deletions tests/github/test_argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
update_pull_request,
)
from pontos.github.models.base import FileStatus
from pontos.testing import temp_directory


class TestArgparsing(unittest.TestCase):
Expand Down Expand Up @@ -105,39 +106,44 @@ def test_update_pr_parse_args_fail(self):
parse_args(argv)

def test_fs_parse_args(self):
argv = [
"FS",
"foo/bar",
"8",
"-o",
"some.file",
]

with patch.dict("os.environ", {}, clear=True):
parsed_args = parse_args(argv)

output = io.open(Path("some.file"), mode="w", encoding="utf-8")

expected_args = Namespace(
command="FS",
func=file_status,
repo="foo/bar",
pull_request=8,
output=output,
status=[FileStatus.ADDED, FileStatus.MODIFIED],
token="GITHUB_TOKEN",
)

self.assertEqual(type(parsed_args.output), type(expected_args.output))
self.assertEqual(parsed_args.command, expected_args.command)
self.assertEqual(parsed_args.func, expected_args.func)
self.assertEqual(parsed_args.repo, expected_args.repo)
self.assertEqual(parsed_args.pull_request, expected_args.pull_request)
self.assertEqual(parsed_args.status, expected_args.status)
self.assertEqual(parsed_args.token, expected_args.token)

output.close()
parsed_args.output.close()
with temp_directory(change_into=True) as tmp_dir:
argv = [
"FS",
"foo/bar",
"8",
"-o",
"some.file",
]

with patch.dict("os.environ", {}, clear=True):
parsed_args = parse_args(argv)

output = open(tmp_dir / "some.file", mode="w", encoding="utf-8")

expected_args = Namespace(
command="FS",
func=file_status,
repo="foo/bar",
pull_request=8,
output=output,
status=[FileStatus.ADDED, FileStatus.MODIFIED],
token="GITHUB_TOKEN",
)

self.assertEqual(
type(parsed_args.output), type(expected_args.output)
)
self.assertEqual(parsed_args.command, expected_args.command)
self.assertEqual(parsed_args.func, expected_args.func)
self.assertEqual(parsed_args.repo, expected_args.repo)
self.assertEqual(
parsed_args.pull_request, expected_args.pull_request
)
self.assertEqual(parsed_args.status, expected_args.status)
self.assertEqual(parsed_args.token, expected_args.token)

output.close()
parsed_args.output.close()

def test_create_release_parse_args(self):
argv = [
Expand Down

0 comments on commit e282290

Please sign in to comment.