diff --git a/.travis.yml b/.travis.yml index 8b9bc9d..5ec9e19 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,8 @@ python: - '3.6' install: - pip install -r requirements.txt +script: + - pytest deploy: provider: pypi user: Dev-Oss diff --git a/liccheck/command_line.py b/liccheck/command_line.py index d39d3dd..b7c0dc0 100644 --- a/liccheck/command_line.py +++ b/liccheck/command_line.py @@ -7,6 +7,7 @@ import sys import pkg_resources + try: from pip._internal.download import PipSession except ImportError: @@ -165,15 +166,22 @@ def read_strategy(strategy_file): return strategy -def main(): +def parse_args(args): parser = argparse.ArgumentParser(description='Check license of packages and there dependencies.') parser.add_argument('-s', '--sfile', dest='strategy_ini_file', help='strategy ini file', required=True) parser.add_argument('-r', '--rfile', dest='requirement_txt_file', help='path/to/requirement.txt file', nargs='?', default='./requirements.txt') - args = parser.parse_args() + return parser.parse_args(args) + +def run(args): strategy = read_strategy(args.strategy_ini_file) - sys.exit(process(args.requirement_txt_file, strategy)) + return process(args.requirement_txt_file, strategy) + + +def main(): + args = parse_args(sys.argv[1:]) + sys.exit(run(args)) if __name__ == "__main__": diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..0caf02f --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,23 @@ +from liccheck.command_line import parse_args, read_strategy, run + + +def test_parse_arguments(): + args = parse_args(['--sfile', 'my_strategy.ini']) + assert args.strategy_ini_file == 'my_strategy.ini' + assert args.requirement_txt_file == './requirements.txt' + args = parse_args(['--sfile', 'my_strategy.ini', '--rfile', 'my_requirements.txt']) + assert args.strategy_ini_file == 'my_strategy.ini' + assert args.requirement_txt_file == 'my_requirements.txt' + + +def test_read_strategy(): + args = parse_args(['--sfile', '../license_strategy.ini']) + strategy = read_strategy(args.strategy_ini_file) + assert len(strategy.AUTHORIZED_LICENSES) > 0 + assert len(strategy.AUTHORIZED_PACKAGES) > 0 + assert len(strategy.UNAUTHORIZED_LICENSES) > 0 + + +def test_run(): + args = parse_args(['--sfile', '../license_strategy.ini', '--rfile', '../requirements.txt']) + run(args)