Thu, 26 Aug 2021 19:49:55 +0300
Fix merge issues regarding the unit tests
ldcheck.py | file | annotate | diff | comparison | revisions | |
unittest.py | file | annotate | diff | comparison | revisions |
--- a/ldcheck.py Thu Aug 26 19:43:03 2021 +0300 +++ b/ldcheck.py Thu Aug 26 19:49:55 2021 +0300 @@ -18,6 +18,9 @@ import header import parse +from os.path import realpath +script_directory = Path(realpath(__file__)).parent + def check_library_paths(library_paths): for library_path in library_paths: if not library_path.exists(): @@ -52,10 +55,8 @@ Contains context-dependant LDraw information, like library directory paths and the colour table. ''' - def __init__(self, libraries = None): + def __init__(self, libraries): self._libraries = libraries - if not self._libraries: - self._libraries = ldraw_dirs_from_config() self.ldconfig_colour_data = self.load_ldconfig_ldr() self.check_library_paths() @property @@ -113,14 +114,16 @@ def is_valid_colour(self, colour): return self.is_ldconfig_colour(colour) or colour.is_direct_colour -def parse_commandline_arguments(): +def load_rcfile(): import os rcpath = Path(os.path.expanduser('~/.config/ldcheckrc')) if rcpath.exists(): with rcpath.open() as file: - rcargs = ['--' + line.strip() for line in file] + return ['--' + line.strip() for line in file] else: - rcargs = [] + return [] + +def parse_commandline_arguments(): import argparse class ListProblemTypesAction(argparse.Action): def __init__(self, option_strings, dest, nargs = None, **kwargs): @@ -170,8 +173,7 @@ version = version_string, ), ) - arglist = rcargs + sys.argv[1:] - return parser.parse_args(arglist) + return parser.parse_args(load_rcfile() + sys.argv[1:]) def format_report(report, model, test_suite, *, use_colors = True): from testsuite import problem_text @@ -198,6 +200,10 @@ messages.append(message) return '\n'.join(messages) +def postprocess_library_paths(libraries_strings): + import os + return [Path(os.path.expanduser(library)) for library in libraries_strings] + def main(): args = parse_commandline_arguments() # Make sure that we have at least one library path specified. @@ -209,7 +215,7 @@ # Prepare the list of libraries. This also expands the ~ for the home # directory import os - libraries = [Path(os.path.expanduser(library)) for library in args.library] + libraries = postprocess_library_paths(args.library) check_library_paths(libraries) load_ldconfig(libraries) try:
--- a/unittest.py Thu Aug 26 19:43:03 2021 +0300 +++ b/unittest.py Thu Aug 26 19:49:55 2021 +0300 @@ -101,12 +101,15 @@ return problem_tuple[0] + ':' + str(problem_tuple[1]) def run_unit_test_suite(): + import sys from argparse import ArgumentParser + from ldcheck import load_rcfile, LDrawContext, postprocess_library_paths parser = ArgumentParser() parser.add_argument('-d', '--debug', action = 'store_true') - args = parser.parse_args() - from ldcheck import LDrawContext - context = LDrawContext() + parser.add_argument('-l', '--library', action = 'append') + parser.add_argument('--color', action = 'store_true') + args = parser.parse_args(load_rcfile() + sys.argv[1:]) + context = LDrawContext(libraries = postprocess_library_paths(args.library)) test_suite = load_tests() num_tested = 0 num_passed = 0