Skip to content

Commit

Permalink
Merge pull request #11 from dumbturtle/issue/#10
Browse files Browse the repository at this point in the history
Issue/#10
  • Loading branch information
Melevir authored Jun 19, 2020
2 parents 03ca968 + f1ef49c commit 4be4647
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
27 changes: 8 additions & 19 deletions mr_proper/main.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import click
import os
import sys
import argparse

from mr_proper.public_api import is_function_pure
from mr_proper.utils.ast import get_ast_tree, get_all_funcdefs_from


def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument('file_or_directory', type=str)
parser.add_argument('--recursive', action='store_true')
return parser.parse_args()


def check_file(path_to_file: str, recursive: bool) -> None:
ast_tree = get_ast_tree(path_to_file)
if not ast_tree:
Expand All @@ -36,17 +29,13 @@ def check_file(path_to_file: str, recursive: bool) -> None:
sys.stdout.write(f'\t{error}\n')


def main() -> None:
recursive = False
args = parse_args()
if not os.path.exists(args.file_or_directory):
sys.stdout.write('File or directory not exist!\n')
return
path_to_files = [args.file_or_directory]
if args.recursive:
recursive = args.recursive
if os.path.isdir(args.file_or_directory):
directoty_path = os.path.abspath(args.file_or_directory)
@click.command()
@click.option('--recursive', is_flag=True, help='Recursive')
@click.argument('file_or_directory', type=click.Path(exists=True))
def main(file_or_directory: str, recursive: bool) -> None:
path_to_files = [file_or_directory]
if os.path.isdir(file_or_directory):
directoty_path = os.path.abspath(file_or_directory)
path_to_files = [
os.path.join(root, filename) for root, dirs, files in os.walk(directoty_path) for filename in files
]
Expand Down
19 changes: 19 additions & 0 deletions tests/test_check_file_or_directory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest

from click.testing import CliRunner
from mr_proper.main import main


@pytest.mark.parametrize(
'file_or_directory_path, check_result',
[
('/test/test_files/dir_not_exist/', 'does not exist'),
('/test/test_files/file_not_exist.py', 'does not exist'),
('tests/test_files/test.py', 'tests/test_files/test.py:' and 'foo is pure!'),
('tests/test_files/errored.py', 'tests/test_files/errored.py:' and 'Error parsing ast tree'),
],
)
def test_is_not_exist(file_or_directory_path, check_result):
runner = CliRunner()
test_result = runner.invoke(main, file_or_directory_path)
assert check_result in test_result.output

0 comments on commit 4be4647

Please sign in to comment.