Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbrzt committed Jun 6, 2024
1 parent 4747669 commit b3f9e01
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def test_session_default_header_value_overwritten(self, httpbin):
def test_download_in_session(self, tmp_path, httpbin):
# https://github.com/httpie/cli/issues/412
self.start_session(httpbin)
with cd_clean_tmp_dir():
with cd_clean_tmp_dir(assert_filenames_after=['get.json']):
http('--session=test', '--download',
httpbin + '/get', env=self.env())

Expand Down
8 changes: 4 additions & 4 deletions tests/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,15 @@ def dump_stderr():


@contextlib.contextmanager
def cd_clean_tmp_dir(assert_filenames_after: list = None):
"""Run commands inside a clean temporary directory, optionally checking for created file names."""
def cd_clean_tmp_dir(assert_filenames_after = []):
"""Run commands inside a clean temporary directory, and verify created file names."""
orig_cwd = os.getcwd()
with tempfile.TemporaryDirectory() as tmp_dirname:
os.chdir(tmp_dirname)
assert os.listdir('.') == []
try:
yield tmp_dirname
if assert_filenames_after is not None:
assert os.listdir('.') == assert_filenames_after
actual_filenames = os.listdir('.')
assert actual_filenames == assert_filenames_after, (actual_filenames, assert_filenames_after)
finally:
os.chdir(orig_cwd)

0 comments on commit b3f9e01

Please sign in to comment.