Skip to content

Commit 278f9ed

Browse files
authored
Merge pull request #28 from digitronik/fix_link_summary
RFR: No more full summary if link count zero
2 parents ce4f416 + a7ae342 commit 278f9ed

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

linkstatus/linkstatus.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ def main(source, recursive, timeout, retry):
6868
down_count = 0
6969
skip_count = 0
7070

71-
files = all_files(source, recursive=recursive)
71+
if source:
72+
files = all_files(source, recursive=recursive)
73+
else:
74+
click.echo("Source Not Found")
75+
click.echo("Run 'linkstatus --help' for more information.")
76+
exit(1)
7277

7378
for f in files:
7479
links = parse_file(f)
@@ -114,18 +119,22 @@ def main(source, recursive, timeout, retry):
114119
)
115120

116121
# Print summary
117-
columns = get_terminal_size().columns
118-
click.echo("=" * columns)
119-
click.echo(click.style("Links Status Summary".center(columns), bold=True))
120-
click.echo(click.style("Links UP: {}".format(up_count).center(columns), fg="green"))
121-
click.echo(click.style("Links SKIP: {}".format(skip_count).center(columns), fg="blue"))
122-
click.echo(click.style("Links DOWN: {}".format(down_count).center(columns), fg="red"))
123-
124-
if exit_code == 1:
125-
click.echo(
126-
"Warning: Use `noqa` inline comment to skip link check. "
127-
"like, response code 403 due to header restrictions etc..."
128-
)
129-
130-
click.echo("=" * columns)
122+
total_links = up_count + skip_count + down_count
123+
124+
if total_links:
125+
columns = get_terminal_size().columns
126+
click.echo("=" * columns)
127+
click.echo(click.style("Links Status Summary".center(columns), bold=True))
128+
click.echo(click.style("Links UP: {}".format(up_count).center(columns), fg="green"))
129+
click.echo(click.style("Links SKIP: {}".format(skip_count).center(columns), fg="blue"))
130+
click.echo(click.style("Links DOWN: {}".format(down_count).center(columns), fg="red"))
131+
132+
if exit_code == 1:
133+
click.echo(
134+
"Warning: Use `noqa` inline comment to skip link check. "
135+
"like, response code 403 due to header restrictions etc..."
136+
)
137+
click.echo("=" * columns)
138+
else:
139+
click.echo("No link found")
131140
exit(exit_code)

tests/test_linkstatus.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import os
2+
import subprocess
3+
4+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
25

36

47
def test_linkstatus_command():
5-
return_code = os.system("linkstatus")
6-
assert return_code == 0
8+
result = subprocess.run("linkstatus", stdout=subprocess.PIPE)
9+
assert result.returncode == 1
10+
assert "Source Not Found" in result.stdout.decode()
11+
assert "Run 'linkstatus --help' for more information." in result.stdout.decode()
12+
13+
14+
def test_linkstatus_command_with_source():
15+
src = os.path.join(BASE_DIR, "conftest.py")
16+
result = subprocess.run(["linkstatus", src], stdout=subprocess.PIPE)
17+
assert result.returncode == 0
18+
assert result.stdout.decode().strip() == "No link found"

0 commit comments

Comments
 (0)