Skip to content

Commit

Permalink
Merge pull request #28 from digitronik/fix_link_summary
Browse files Browse the repository at this point in the history
RFR: No more full summary if link count zero
  • Loading branch information
raukadah authored Feb 27, 2020
2 parents ce4f416 + a7ae342 commit 278f9ed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
39 changes: 24 additions & 15 deletions linkstatus/linkstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ def main(source, recursive, timeout, retry):
down_count = 0
skip_count = 0

files = all_files(source, recursive=recursive)
if source:
files = all_files(source, recursive=recursive)
else:
click.echo("Source Not Found")
click.echo("Run 'linkstatus --help' for more information.")
exit(1)

for f in files:
links = parse_file(f)
Expand Down Expand Up @@ -114,18 +119,22 @@ def main(source, recursive, timeout, retry):
)

# Print summary
columns = get_terminal_size().columns
click.echo("=" * columns)
click.echo(click.style("Links Status Summary".center(columns), bold=True))
click.echo(click.style("Links UP: {}".format(up_count).center(columns), fg="green"))
click.echo(click.style("Links SKIP: {}".format(skip_count).center(columns), fg="blue"))
click.echo(click.style("Links DOWN: {}".format(down_count).center(columns), fg="red"))

if exit_code == 1:
click.echo(
"Warning: Use `noqa` inline comment to skip link check. "
"like, response code 403 due to header restrictions etc..."
)

click.echo("=" * columns)
total_links = up_count + skip_count + down_count

if total_links:
columns = get_terminal_size().columns
click.echo("=" * columns)
click.echo(click.style("Links Status Summary".center(columns), bold=True))
click.echo(click.style("Links UP: {}".format(up_count).center(columns), fg="green"))
click.echo(click.style("Links SKIP: {}".format(skip_count).center(columns), fg="blue"))
click.echo(click.style("Links DOWN: {}".format(down_count).center(columns), fg="red"))

if exit_code == 1:
click.echo(
"Warning: Use `noqa` inline comment to skip link check. "
"like, response code 403 due to header restrictions etc..."
)
click.echo("=" * columns)
else:
click.echo("No link found")
exit(exit_code)
16 changes: 14 additions & 2 deletions tests/test_linkstatus.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import os
import subprocess

BASE_DIR = os.path.dirname(os.path.abspath(__file__))


def test_linkstatus_command():
return_code = os.system("linkstatus")
assert return_code == 0
result = subprocess.run("linkstatus", stdout=subprocess.PIPE)
assert result.returncode == 1
assert "Source Not Found" in result.stdout.decode()
assert "Run 'linkstatus --help' for more information." in result.stdout.decode()


def test_linkstatus_command_with_source():
src = os.path.join(BASE_DIR, "conftest.py")
result = subprocess.run(["linkstatus", src], stdout=subprocess.PIPE)
assert result.returncode == 0
assert result.stdout.decode().strip() == "No link found"

0 comments on commit 278f9ed

Please sign in to comment.