()
| 601 | |
| 602 | |
| 603 | def test(): |
| 604 | # Parse command line |
| 605 | import getopt |
| 606 | try: |
| 607 | opts, args = getopt.getopt(sys.argv[1:], "dmp:qx:") |
| 608 | except getopt.error as msg: |
| 609 | print(msg) |
| 610 | return |
| 611 | |
| 612 | # Process options |
| 613 | debug = 1 |
| 614 | domods = 0 |
| 615 | addpath = [] |
| 616 | exclude = [] |
| 617 | for o, a in opts: |
| 618 | if o == '-d': |
| 619 | debug = debug + 1 |
| 620 | if o == '-m': |
| 621 | domods = 1 |
| 622 | if o == '-p': |
| 623 | addpath = addpath + a.split(os.pathsep) |
| 624 | if o == '-q': |
| 625 | debug = 0 |
| 626 | if o == '-x': |
| 627 | exclude.append(a) |
| 628 | |
| 629 | # Provide default arguments |
| 630 | if not args: |
| 631 | script = "hello.py" |
| 632 | else: |
| 633 | script = args[0] |
| 634 | |
| 635 | # Set the path based on sys.path and the script directory |
| 636 | path = sys.path[:] |
| 637 | path[0] = os.path.dirname(script) |
| 638 | path = addpath + path |
| 639 | if debug > 1: |
| 640 | print("path:") |
| 641 | for item in path: |
| 642 | print(" ", repr(item)) |
| 643 | |
| 644 | # Create the module finder and turn its crank |
| 645 | mf = ModuleFinder(path, debug, exclude) |
| 646 | for arg in args[1:]: |
| 647 | if arg == '-m': |
| 648 | domods = 1 |
| 649 | continue |
| 650 | if domods: |
| 651 | if arg[-2:] == '.*': |
| 652 | mf.import_hook(arg[:-2], None, ["*"]) |
| 653 | else: |
| 654 | mf.import_hook(arg) |
| 655 | else: |
| 656 | mf.load_file(arg) |
| 657 | mf.run_script(script) |
| 658 | mf.report() |
| 659 | return mf # for -i debugging |
| 660 |
no test coverage detected