1 | import json |
---|
2 | import sys |
---|
3 | from CacheLib import ( |
---|
4 | ogCreateCache, ogDeleteCache, ogFindCache, ogFormatCache, |
---|
5 | ogGetCacheSize, ogGetCacheSpace, ogMountCache, ogUnmountCache, |
---|
6 | ogRaiseError |
---|
7 | ) |
---|
8 | |
---|
9 | def load_test_data(file_path): |
---|
10 | with open(file_path, 'r') as file: |
---|
11 | return json.load(file) |
---|
12 | |
---|
13 | def test_ogCreateCache(test_cases): |
---|
14 | for case in test_cases: |
---|
15 | try: |
---|
16 | ogCreateCache(**case) |
---|
17 | print(f"ogCreateCache({case}) pasó la prueba") |
---|
18 | except Exception as e: |
---|
19 | print(f"ogCreateCache({case}) falló la prueba: {e}") |
---|
20 | |
---|
21 | def test_ogDeleteCache(test_cases): |
---|
22 | for case in test_cases: |
---|
23 | try: |
---|
24 | ogDeleteCache() |
---|
25 | print(f"ogDeleteCache() pasó la prueba") |
---|
26 | except Exception as e: |
---|
27 | print(f"ogDeleteCache() falló la prueba: {e}") |
---|
28 | |
---|
29 | def test_ogFindCache(test_cases): |
---|
30 | for case in test_cases: |
---|
31 | try: |
---|
32 | result = ogFindCache() |
---|
33 | print(f"ogFindCache() pasó la prueba, resultado: {result}") |
---|
34 | except Exception as e: |
---|
35 | print(f"ogFindCache() falló la prueba: {e}") |
---|
36 | |
---|
37 | def test_ogFormatCache(test_cases): |
---|
38 | for case in test_cases: |
---|
39 | try: |
---|
40 | ogFormatCache() |
---|
41 | print(f"ogFormatCache() pasó la prueba") |
---|
42 | except Exception as e: |
---|
43 | print(f"ogFormatCache() falló la prueba: {e}") |
---|
44 | |
---|
45 | def test_ogGetCacheSize(test_cases): |
---|
46 | for case in test_cases: |
---|
47 | try: |
---|
48 | result = ogGetCacheSize() |
---|
49 | print(f"ogGetCacheSize() pasó la prueba, tamaño: {result} KB") |
---|
50 | except Exception as e: |
---|
51 | print(f"ogGetCacheSize() falló la prueba: {e}") |
---|
52 | |
---|
53 | def test_ogGetCacheSpace(test_cases): |
---|
54 | for case in test_cases: |
---|
55 | try: |
---|
56 | result = ogGetCacheSpace() |
---|
57 | print(f"ogGetCacheSpace() pasó la prueba, espacio libre: {result} KB") |
---|
58 | except Exception as e: |
---|
59 | print(f"ogGetCacheSpace() falló la prueba: {e}") |
---|
60 | |
---|
61 | def test_ogMountCache(test_cases): |
---|
62 | for case in test_cases: |
---|
63 | try: |
---|
64 | ogMountCache(**case) |
---|
65 | print(f"ogMountCache({case}) pasó la prueba") |
---|
66 | except Exception as e: |
---|
67 | print(f"ogMountCache({case}) falló la prueba: {e}") |
---|
68 | |
---|
69 | def test_ogUnmountCache(test_cases): |
---|
70 | for case in test_cases: |
---|
71 | try: |
---|
72 | ogUnmountCache() |
---|
73 | print(f"ogUnmountCache() pasó la prueba") |
---|
74 | except Exception as e: |
---|
75 | print(f"ogUnmountCache() falló la prueba: {e}") |
---|
76 | |
---|
77 | def run_tests(test_data): |
---|
78 | test_ogCreateCache(test_data.get("ogCreateCache", [])) |
---|
79 | test_ogDeleteCache(test_data.get("ogDeleteCache", [])) |
---|
80 | test_ogFindCache(test_data.get("ogFindCache", [])) |
---|
81 | test_ogFormatCache(test_data.get("ogFormatCache", [])) |
---|
82 | test_ogGetCacheSize(test_data.get("ogGetCacheSize", [])) |
---|
83 | test_ogGetCacheSpace(test_data.get("ogGetCacheSpace", [])) |
---|
84 | test_ogMountCache(test_data.get("ogMountCache", [])) |
---|
85 | test_ogUnmountCache(test_data.get("ogUnmountCache", [])) |
---|
86 | |
---|
87 | if __name__ == "__main__": |
---|
88 | if len(sys.argv) != 2: |
---|
89 | print("Uso: python3 test_CacheLib.py <ruta_al_archivo_json>") |
---|
90 | sys.exit(1) |
---|
91 | |
---|
92 | test_data_file = sys.argv[1] |
---|
93 | test_data = load_test_data(test_data_file) |
---|
94 | run_tests(test_data) |
---|
95 | |
---|