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