Skip to content

Commit 905f674

Browse files
committed
#425: tests added and passing
1 parent 928024f commit 905f674

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Copyright © 2000 ACME, Inc., All Rights Reserved */

tests/scancode/test_cli.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,34 @@ def _load_json_result(result_file):
8585
return scan_result
8686

8787

88+
def test_json_pretty_print_option(monkeypatch):
89+
monkeypatch.setattr(click._termui_impl, 'isatty', lambda _: True)
90+
test_dir = test_env.get_test_loc('json-option', copy=True)
91+
runner = CliRunner()
92+
result_file = test_env.get_temp_file('json')
93+
result = runner.invoke(cli.scancode, ['--copyright', '--format', 'json-pp', test_dir, result_file], catch_exceptions=True)
94+
assert result.exit_code == 0
95+
assert 'Scanning done' in result.output
96+
assert 'copyright_acme_c-c.c' in result.output
97+
assert os.path.exists(result_file)
98+
assert len(open(result_file).read()) > 10
99+
assert len(open(result_file).readlines()) > 1
100+
101+
102+
def test_json_output_option_is_minified(monkeypatch):
103+
monkeypatch.setattr(click._termui_impl, 'isatty', lambda _: True)
104+
test_dir = test_env.get_test_loc('json-option', copy=True)
105+
runner = CliRunner()
106+
result_file = test_env.get_temp_file('json')
107+
result = runner.invoke(cli.scancode, ['--copyright', '--format', 'json', test_dir, result_file], catch_exceptions=True)
108+
assert result.exit_code == 0
109+
assert 'Scanning done' in result.output
110+
assert 'copyright_acme_c-c.c' in result.output
111+
assert os.path.exists(result_file)
112+
assert len(open(result_file).read()) > 10
113+
assert len(open(result_file).readlines()) == 1
114+
115+
88116
def test_package_option_detects_packages(monkeypatch):
89117
monkeypatch.setattr(click._termui_impl, 'isatty', lambda _: True)
90118
test_dir = test_env.get_test_loc('package', copy=True)

0 commit comments

Comments
 (0)