Skip to content

Commit

Permalink
UI fixes (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-treebeard committed Mar 12, 2021
1 parent 52def68 commit e6ff971
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 129 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
],
"menus": {
"editor/title": [
{
"command": "deeptest.toggleDeeptest",
"group": "navigation"
}
{
"command": "deeptest.toggleDeeptest",
"group": "navigation"
}
]
}
}
},
"scripts": {
"vscode:prepublish": "yarn run compile",
Expand All @@ -64,5 +64,6 @@
"typescript": "^4.1.3",
"vscode-test": "^1.5.0"
},
"dependencies": {}
"dependencies": {
}
}
13 changes: 12 additions & 1 deletion python-cli/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions python-cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rich = "^9.13.0"
pydantic = "^1.8.1"
coverage = "^5.5"
junitparser = "^2.0.0"
timeago = "^1.0.15"

[tool.poetry.dev-dependencies]
pytest = "^6.2.2"
Expand Down
31 changes: 26 additions & 5 deletions python-cli/src/deeptest/cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import json
import os
import sys
from datetime import datetime
from enum import Enum
from pathlib import Path
from typing import Dict, List, cast
from typing import Dict, List, Optional, cast

import click
import timeago
from coverage import Coverage, CoverageData
from coverage.misc import NoSource
from junitparser import JUnitXml
Expand Down Expand Up @@ -73,9 +75,23 @@ def get_file_cov(src: str, coverage: Coverage, coverage_data: CoverageData):


@click.command()
@click.argument("source")
def run(source: str):
@click.argument("source", required=False)
@click.option("--data-dir", default=None)
def run(source: Optional[str], data_dir: Optional[str]):
""""""
if data_dir:
Path(data_dir).mkdir(exist_ok=True, parents=True)
os.chdir(data_dir)

if source is None:
if Path(".coverage").exists():
stats = os.stat(".coverage")
dt = datetime.fromtimestamp(stats.st_mtime)
ago = timeago.format(dt, datetime.now())
click.echo(json.dumps({"time_since_run": ago}))
else:
click.echo(json.dumps({"time_since_run": None}))
sys.exit(0)
src = Path(source).as_posix()
test_results = Path("junit.xml")
if not test_results.exists():
Expand Down Expand Up @@ -108,8 +124,13 @@ def run(source: str):
assert coverage_data is not None
lines, missing_lines = get_file_cov(src, coverage, coverage_data)

norm_contexts = {norm(ctx) for ctx in coverage_data.measured_contexts()}
assert norm_contexts.difference(status.keys()) == set()
# norm_contexts = {norm(ctx) for ctx in coverage_data.measured_contexts()}

# no_matching_key = norm_contexts.difference(status.keys())

# if len(no_matching_key)> 0:
# lkj = '\n'.join(no_matching_key)
# click.echo(f"No matching key:{lkj} ")

file = File(
lines={
Expand Down
10 changes: 10 additions & 0 deletions python-cli/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,13 @@ def test_when_out_of_cov_scope_then_error(self, tested_dir: object):
print(f"Running {source}")
result = runner.invoke(cli.run, source.as_posix(), catch_exceptions=False)
assert json.loads(result.stdout)["error"].startswith("No cov")

def test_when_status_then_time_given(self, tested_dir: object):
runner = CliRunner()
result = runner.invoke(cli.run, catch_exceptions=False)
assert json.loads(result.stdout)["time_since_run"] == "just now"

def test_when_status_no_data_then_null(self, testdir: pytest.Testdir):
runner = CliRunner()
result = runner.invoke(cli.run, catch_exceptions=False)
assert json.loads(result.stdout)["time_since_run"] == None
Loading

0 comments on commit e6ff971

Please sign in to comment.