ratchets

Mirror of ratchets, my python testing utility
git clone git://git.laack.co/ratchets.git
Log | Files | Refs | README | LICENSE

test_exclusion.py (2501B)


      1 from ratchets import run_tests
      2 from ratchets import abstracted_tests
      3 import os
      4 import shutil
      5 
      6 
      7 def test_config():
      8     test_path = os.path.join(
      9         run_tests.find_project_root(), "tests/toml_files/default.toml"
     10     )
     11 
     12     assert os.path.isfile(test_path), "default.toml not found"
     13 
     14     try:
     15         issues = run_tests.evaluate_tests(test_path, True, True, None)
     16         run_tests.update_ratchets(
     17             test_path,
     18             True,
     19             True,
     20             None,
     21             run_tests.find_project_root() + "/tests/test_files/temp_ratchet1.json",
     22         )
     23     except Exception as e:
     24         assert False, f"Unable to update ratchets using 'tests.toml': {e}"
     25 
     26 
     27 def test_exclusion():
     28 
     29     current_file_directory = os.path.dirname(os.path.abspath(__file__))
     30     excluded_directory = os.path.abspath(
     31         os.path.join(current_file_directory, "..", "excluded_files")
     32     )
     33     test_py_dir = os.path.abspath(
     34         os.path.join(current_file_directory, "..", "python_files")
     35     )
     36     exclusion_path = (
     37         run_tests.find_project_root() + "/tests/exclusion_files/ratchet_excluded.txt"
     38     )
     39 
     40     root = run_tests.find_project_root()
     41     ignore_path = os.path.join(root, ".gitignore")
     42 
     43     python_files_no_exclusion = run_tests.get_python_files(test_py_dir, None)
     44 
     45     # ensure no side effects in the method
     46     # since we don't change the path values,
     47     # ensuring the count reamins the same should suffice
     48 
     49     length_starting = len(python_files_no_exclusion)
     50 
     51     expected_results = {"default_excluded.txt": 6, "no_1.txt": 4, "no_1_or_dir.txt": 3}
     52 
     53     count = 0
     54     for filename in os.listdir(excluded_directory):
     55         count += 1
     56         full_path = os.path.abspath(os.path.join(excluded_directory, filename))
     57         shutil.copy(full_path, exclusion_path)
     58         filtered = run_tests.filter_excluded_files(
     59             python_files_no_exclusion, exclusion_path, ignore_path
     60         )
     61 
     62         assert (
     63             len(python_files_no_exclusion) == length_starting
     64         ), "There is a side effect in filter_excluded_files"
     65 
     66         assert (
     67             filename in expected_results
     68         ), "An additional excluded.txt file was added, but not reflected"
     69 
     70         assert expected_results[filename] == len(
     71             filtered
     72         ), "Filter count differs from expected value"
     73 
     74     assert count == len(
     75         expected_results
     76     ), "There is an extra entry in the expected_results dictionary"
     77 
     78 
     79 if __name__ == "__main__":
     80     test_config()
     81     test_exclusion()