mirror of
https://github.com/bellingcat/tiktok-hashtag-analysis.git
synced 2026-06-07 19:08:32 +03:00
reorganized output directory parsing tests
This commit is contained in:
25
tests/cli.py
25
tests/cli.py
@@ -41,44 +41,57 @@ def test_parser(hashtags, attribute, value, flag):
|
||||
assert args.get("hashtags") == hashtags
|
||||
|
||||
|
||||
def test_process_output_dir(monkeypatch, tmp_path):
|
||||
home_dir = Path.home().resolve()
|
||||
|
||||
def test_output_dir_spec_noexist_nowrite(tmp_path):
|
||||
# Specified nonexistent output directory without write permissions
|
||||
parser = create_parser()
|
||||
specified_output_dir = home_dir.parent / "test"
|
||||
os.chmod(tmp_path, 0o444)
|
||||
specified_output_dir = tmp_path / "test"
|
||||
with pytest.raises(SystemExit) as system_exit:
|
||||
result = process_output_dir(
|
||||
specified_output_dir=specified_output_dir, parser=parser
|
||||
)
|
||||
assert system_exit.type == SystemExit
|
||||
|
||||
|
||||
def test_output_dir_spec_exist_nowrite(tmp_path):
|
||||
# Specified existing output directory without write permissions
|
||||
parser = create_parser()
|
||||
specified_output_dir = home_dir.parent
|
||||
os.chmod(tmp_path, 0o444)
|
||||
specified_output_dir = tmp_path
|
||||
with pytest.raises(SystemExit) as system_exit:
|
||||
result = process_output_dir(
|
||||
specified_output_dir=specified_output_dir, parser=parser
|
||||
)
|
||||
assert system_exit.type == SystemExit
|
||||
|
||||
|
||||
def test_output_dir_unspec_nowrite(monkeypatch, tmp_path):
|
||||
# Unspecified, in current directory without write permissions
|
||||
parser = create_parser()
|
||||
cwd = os.getcwd()
|
||||
specified_output_dir = tmp_path
|
||||
monkeypatch.chdir(specified_output_dir)
|
||||
os.chmod(tmp_path, 0o444)
|
||||
result = process_output_dir(specified_output_dir=None, parser=parser)
|
||||
monkeypatch.chdir(cwd)
|
||||
assert result == DEFAULT_OUTPUT_DIR
|
||||
|
||||
|
||||
def test_output_dir_spec_noexist_write(tmp_path):
|
||||
# Specified nonexisting output directory with write permissions
|
||||
parser = create_parser()
|
||||
specified_output_dir = tmp_path / "test" / "tiktok"
|
||||
specified_output_dir = tmp_path / "test"
|
||||
result = process_output_dir(
|
||||
specified_output_dir=specified_output_dir, parser=parser
|
||||
)
|
||||
assert result == specified_output_dir
|
||||
|
||||
|
||||
def test_output_dir_unspec_write(monkeypatch, tmp_path):
|
||||
# Unspecified, in current directory with write permissions
|
||||
parser = create_parser()
|
||||
cwd = os.getcwd()
|
||||
specified_output_dir = tmp_path
|
||||
monkeypatch.chdir(specified_output_dir)
|
||||
result = process_output_dir(specified_output_dir=None, parser=parser)
|
||||
monkeypatch.chdir(cwd)
|
||||
|
||||
@@ -101,7 +101,7 @@ def process_output_dir(
|
||||
else:
|
||||
# On Windows, os.access is unreliable
|
||||
temp_file = _output_dir / "test.txt"
|
||||
with open(temp_file, 'w') as f:
|
||||
with open(temp_file, "w") as f:
|
||||
f.write("test")
|
||||
os.remove(temp_file)
|
||||
return _output_dir
|
||||
|
||||
Reference in New Issue
Block a user