Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Chédru committed May 4, 2018
1 parent 54dd901 commit 0c87619
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ python:
- '3.6'
install:
- pip install -r requirements.txt
script:
- pytest
deploy:
provider: pypi
user: Dev-Oss
Expand Down
14 changes: 11 additions & 3 deletions liccheck/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys

import pkg_resources

try:
from pip._internal.download import PipSession
except ImportError:
Expand Down Expand Up @@ -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__":
Expand Down
23 changes: 23 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0c87619

Please sign in to comment.