Exemple #1
0
def sanity(ARG_test_directory):
    """Runs the sanity test"""
    os.chdir(ARG_test_directory)
    with open(DATESTRING_SHORT + ".sanity.txt", "w+") as f:
        # Save original stdout and stderr settings
        _old_stdout = sys.stdout
        _old_stderr = sys.stderr
        # Switch stdout and stderr to file output
        sys.stdout = f
        sys.stderr = f

        print(PROJECT_NAME, "test suite results")
        print(DATESTRING)
        formatting.line()
        formatting.header("GENERATOR SANITY TEST")
        print()

        try:
            testsuite = unittest.TestLoader().loadTestsFromModule(sanitytests)
            unittest.TextTestRunner(verbosity=2).run(testsuite)
        except Exception:  # pylint: disable=broad-except
            messages.traceback_message()
            did_test_finish = False
        else:
            did_test_finish = True

        # Restore stdout and stderr to original settings
        sys.stderr = _old_stderr
        sys.stdout = _old_stdout
    return did_test_finish
Exemple #2
0
def unused_imports(ARG_test_directory, ARG_rosevomit_directory):
    """Runs the unused import list test."""
    os.chdir(ARG_test_directory)
    with open(DATESTRING_SHORT + ".imports-unused.txt", "w+") as f:
        # Save original stdout and stderr settings
        _old_stdout = sys.stdout
        _old_stderr = sys.stderr
        # Switch stdout and stderr to file output
        sys.stdout = f
        sys.stderr = f

        print(PROJECT_NAME, "test suite results")
        print(DATESTRING)
        formatting.line()
        formatting.header("UNUSED IMPORTS LIST")
        os.chdir(ARG_rosevomit_directory)
        mock_cli_args = ["rosevomit.py", "-i", "-u"]

        try:
            findimports.main(argv=mock_cli_args)
        except Exception:  # pylint: disable=broad-except
            messages.traceback_message()
            did_test_finish = False
        else:
            did_test_finish = True

        # Restore stdout and stderr to original settings
        sys.stderr = _old_stderr
        sys.stdout = _old_stdout
    return did_test_finish
Exemple #3
0
def performance(ARG_test_directory):
    """Runs the performance test"""
    os.chdir(ARG_test_directory)
    with open(DATESTRING_SHORT + ".perf.txt", "w+") as f:
        # Save original stdout and stderr settings
        _old_stdout = sys.stdout
        _old_stderr = sys.stderr
        # Switch stdout and stderr to file output
        sys.stdout = f
        sys.stderr = f

        print(PROJECT_NAME, "test suite results")
        print(DATESTRING)
        formatting.line()
        formatting.header("PERFORMANCE TEST FULL RESULTS")
        print()

        try:
            print(
                "Rosevomit's performance when generating 10 names (measured in seconds)"
            )
            with testutilities.Suppressor():
                perftest10_results = timetest_name_generation(
                    ARG_number_of_names=10)
            for key, value in perftest10_results.items():
                print(f"   {key}: {value}")
            print()
            print(
                "Rosevomit's performance when generating 100 names (measured in seconds)"
            )
            with testutilities.Suppressor():
                perftest100_results = timetest_name_generation(
                    ARG_number_of_names=100)
            for key, value in perftest100_results.items():
                print(f"   {key}: {value}")
            print()
            print(
                "Rosevomit's performance when generating 1,000 names (measured in seconds)"
            )
            with testutilities.Suppressor():
                perftest1000_results = timetest_name_generation(
                    ARG_number_of_names=1000)
            for key, value in perftest1000_results.items():
                print(f"   {key}: {value}")
        except Exception:  # pylint: disable=broad-except
            messages.traceback_message()

        # Restore stdout and stderr to original settings
        sys.stderr = _old_stderr
        sys.stdout = _old_stdout
    return perftest10_results, perftest100_results, perftest1000_results
Exemple #4
0
def pylint(ARG_test_directory, ARG_repository_directory):
    """Runs a test using pylint"""
    os.chdir(ARG_test_directory)
    with open(DATESTRING_SHORT + ".pylint.txt", "w+") as f:
        # Save original stdout and stderr settings
        _old_stdout = sys.stdout
        _old_stderr = sys.stderr
        # Switch stdout and stderr to file output
        sys.stdout = f
        sys.stderr = f

        print(PROJECT_NAME, "test suite results")
        print(DATESTRING)
        formatting.line()
        formatting.header("pylint")
        os.chdir(ARG_repository_directory)
        # pylint error messages
        #   C0301 line-too-long
        #   C0326 spaces
        #   R1705 no-else-return
        #   E0401 import-error (because they don't seem to work properly for me when running statically)
        pylint_opts = [
            "rosevomit",
            "--rcfile=.pylintrc",
        ]

        try:
            linter.Run(pylint_opts, do_exit=False)
        except Exception:  # pylint: disable=broad-except
            messages.traceback_message()
            did_test_finish = False
        else:
            did_test_finish = True

        # Restore stdout and stderr to original settings
        sys.stderr = _old_stderr
        sys.stdout = _old_stdout
    return did_test_finish