Skip to content

Commit

Permalink
fix: pytests set up with snapshots for all samples
Browse files Browse the repository at this point in the history
  • Loading branch information
Udayraj123 committed Jan 24, 2023
1 parent 278d482 commit b69aa85
Show file tree
Hide file tree
Showing 13 changed files with 440 additions and 58 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
exclude: '__snapshots__/.*$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
Expand Down
122 changes: 70 additions & 52 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,74 @@
from src.entry import entry_point
from src.logger import logger

# construct the argument parse and parse the arguments
argparser = argparse.ArgumentParser()

argparser.add_argument(
"-i",
"--inputDir",
default=["inputs"],
# https://docs.python.org/3/library/argparse.html#nargs
nargs="*",
required=False,
type=str,
dest="input_paths",
help="Specify an input directory.",
)

argparser.add_argument(
"-o",
"--outputDir",
default="outputs",
required=False,
dest="output_dir",
help="Specify an output directory.",
)

argparser.add_argument(
"-l",
"--setLayout",
required=False,
dest="setLayout",
action="store_true",
help="Set up OMR template layout - modify your json file and \
run again until the template is set.",
)


(
args,
unknown,
) = argparser.parse_known_args()
args = vars(args)

# FIX: remove join
if len(unknown) > 0:
logger.warning("".join(["\nError: Unknown arguments: ", unknown]))
argparser.print_help()
exit(11)

for root in args["input_paths"]:
entry_point(
Path(root),
Path(root),
args,

def parse_args():
# construct the argument parse and parse the arguments
argparser = argparse.ArgumentParser()

argparser.add_argument(
"-i",
"--inputDir",
default=["inputs"],
# https://docs.python.org/3/library/argparse.html#nargs
nargs="*",
required=False,
type=str,
dest="input_paths",
help="Specify an input directory.",
)

argparser.add_argument(
"-o",
"--outputDir",
default="outputs",
required=False,
dest="output_dir",
help="Specify an output directory.",
)

argparser.add_argument(
"-a",
"--autoAlign",
required=False,
dest="autoAlign",
action="store_true",
help="(experimental) Enables automatic template alignment - \
use if the scans show slight misalignments.",
)

argparser.add_argument(
"-l",
"--setLayout",
required=False,
dest="setLayout",
action="store_true",
help="Set up OMR template layout - modify your json file and \
run again until the template is set.",
)

(
args,
unknown,
) = argparser.parse_known_args()

args = vars(args)

if len(unknown) > 0:
logger.warning(f"\nError: Unknown arguments: {unknown}", unknown)
argparser.print_help()
exit(11)
return args


def entry_point_for_args(args):
for root in args["input_paths"]:
entry_point(
Path(root),
args,
)


if __name__ == "__main__":
args = parse_args()
entry_point_for_args(args)
6 changes: 6 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# pytest.ini
[pytest]
minversion = 7.0
addopts = -qq --capture=no
testpaths =
src/tests
4 changes: 4 additions & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
-r requirements.txt
pytest>=7.1.3
pytest-mock>=3.10.0
syrupy>=3.0.6
freezegun>=1.2.2
pre-commit
Binary file added samples/community/UmarFarootAPS/scans/Scan1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/community/UmarFarootAPS/scans/Scan2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified samples/community/UmarFarootAPS/scans/scan-type-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions src/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
STATS = Stats()


def entry_point(input_dir, curr_dir, args):
def entry_point(input_dir, args):
if not os.path.exists(input_dir):
raise Exception(f"Given input directory does not exist: '{input_dir}'")
curr_dir = input_dir
return process_dir(input_dir, curr_dir, args)


Expand Down Expand Up @@ -96,12 +97,12 @@ def process_dir(
logger.info(f'Processing directory "{curr_dir}" with settings- ')
logger.info(f"\t{'Total images':<22}: {len(omr_files)}")
logger.info(
f"\t{'Cropping Enabled':<22}: {str('CropOnMarkers' in template.pre_processors)}"
f"\t{'Cropping Enabled':<22}: {'CropOnMarkers' in template.pre_processors}"
)
logger.info(
f"\t{'Auto Alignment':<22}: {tuning_config.alignment_params.auto_align}"
)
logger.info(f"\t{'Using Template':<22}: { str(template)}")
logger.info(f"\t{'Using Template':<22}: {template}")
logger.info(
f"\t{'Using pre-processors':<22}: {[pp.__class__.__name__ for pp in template.pre_processors]}"
)
Expand Down Expand Up @@ -311,7 +312,7 @@ def process_files(


def print_stats(start_time, files_counter, tuning_config):
time_checking = round(time() - start_time, 2) if files_counter else 1
time_checking = max(1, round(time() - start_time, 2))
log = logger.info
log("")
log(f"{'Total file(s) moved':<27}: {STATS.files_moved}")
Expand Down
2 changes: 1 addition & 1 deletion src/processors/CropPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def apply_filter(self, image, file_path):

# Resize should be done with another preprocessor is needed
sheet = self.find_page(image, file_path)
if sheet == []:
if len(sheet) == 0:
logger.error(
f"\tError: Paper boundary not found for: '{file_path}'\nHave you accidentally included CropPage preprocessor?"
)
Expand Down
1 change: 1 addition & 0 deletions src/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# https://stackoverflow.com/a/50169991/6242649
Loading

0 comments on commit b69aa85

Please sign in to comment.