From 0ac3f60647a97d2877f086cf0a5d159276cc20b0 Mon Sep 17 00:00:00 2001 From: Nikhil Dhandre Date: Sat, 27 Jun 2020 19:45:07 +0530 Subject: [PATCH] Increase code cov --- tests/test_linkstatus.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/test_linkstatus.py b/tests/test_linkstatus.py index 1360cca..d2c8ed8 100644 --- a/tests/test_linkstatus.py +++ b/tests/test_linkstatus.py @@ -1,7 +1,10 @@ import os import subprocess +from pathlib import Path -BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +import pytest + +BASE_DIR = Path(os.path.dirname(os.path.abspath(__file__))) def test_linkstatus_command(): @@ -11,8 +14,18 @@ def test_linkstatus_command(): 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" +@pytest.mark.parametrize( + "file", + [BASE_DIR / "conftest.py", BASE_DIR / "data" / "text_file"], + ids=["no-link", "with-link"], +) +def test_linkstatus_command_with_source(file): + result = subprocess.run(["linkstatus", file], stdout=subprocess.PIPE) + data = result.stdout.decode().strip() + + if file.name == "text_file": + assert result.returncode == 1 + assert all([check in data for check in ["Links SKIP: 0", "Links DOWN: 1", "Links UP: 3"]]) + else: + assert result.returncode == 0 + assert data == "No link found"