Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_exists_older(tmpdir):
"""
Test that exists() returns true if path does exist
and has a file with the version older than the current
"""
config = DEFAULT_CONFIG
tmp_path = pathlib.Path(tmpdir)
config.cache_path = tmp_path / ".wily"
(tmp_path / ".wily").mkdir()
with open((tmp_path / ".wily" / "index.json"), "w+") as index:
index.write('{"version": "0.1.0"}')
assert cache.exists(config)
def test_not_exists():
"""
Test that exists() returns false if path does not exist
"""
config = DEFAULT_CONFIG
config.cache_path = "/v/v/w"
assert not cache.exists(config)
def test_clean_when_not_exists(tmpdir):
"""
Test that clean() will continue if the folder does not exist
"""
config = DEFAULT_CONFIG
cache_path = pathlib.Path(tmpdir) / ".wily"
config.cache_path = str(cache_path)
assert not cache.exists(config)
assert cache.clean(config) is None
def test_create_when_exists(tmpdir):
"""
Test that create() will continue if the folder already exists
"""
config = DEFAULT_CONFIG
cache_path = pathlib.Path(tmpdir) / ".wily"
pathlib.Path(cache_path).mkdir()
config.cache_path = str(cache_path)
assert cache.exists(config)
assert str(cache.create(config)) == str(cache_path)
def test_create_and_delete(tmpdir):
"""
Test that create() will create a folder with the correct path
and then delete it.
"""
config = DEFAULT_CONFIG
cache_path = pathlib.Path(tmpdir) / ".wily"
config.cache_path = str(cache_path)
assert not cache.exists(config)
cache.create(config)
assert cache.exists(config)
cache.clean(config)
assert not cache.exists(config)
Graph all .py files within src/ for the raw.loc metric
$ wily graph src/ raw.loc
Graph test.py against raw.loc and cyclomatic.complexity metrics
$ wily graph src/test.py raw.loc cyclomatic.complexity
Graph test.py against raw.loc and raw.sloc on the x-axis
$ wily graph src/test.py raw.loc --x-axis raw.sloc
"""
config = ctx.obj["CONFIG"]
if not exists(config):
handle_no_cache(ctx)
from wily.commands.graph import graph
logger.debug(f"Running report on {path} for metrics {metrics}")
graph(
config=config,
path=path,
metrics=metrics,
output=output,
x_axis=x_axis,
changes=changes,
)
def report(ctx, file, metrics, number, message, format, console_format, output):
"""Show metrics for a given file."""
config = ctx.obj["CONFIG"]
if not exists(config):
handle_no_cache(ctx)
if not metrics:
metrics = get_default_metrics(config)
logger.info(f"Using default metrics {metrics}")
new_output = Path().cwd()
if output:
new_output = new_output / Path(output)
else:
new_output = new_output / "wily_report" / "index.html"
from wily.commands.report import report
logger.debug(f"Running report on {file} for metric {metrics}")
logger.debug(f"Output format is {format}")