|
| 1 | +import pytest |
| 2 | +from scripts.microgenerator.generate import ( |
| 3 | + _should_include_class, |
| 4 | + _should_include_method, |
| 5 | +) |
| 6 | + |
| 7 | + |
| 8 | +# Tests for _should_include_class |
| 9 | +@pytest.mark.parametrize( |
| 10 | + "class_name, filters, expected", |
| 11 | + [ |
| 12 | + pytest.param("MyClass", {}, True, id="No filters"), |
| 13 | + pytest.param( |
| 14 | + "DatasetClient", |
| 15 | + {"include_suffixes": ["Client", "Service"]}, |
| 16 | + True, |
| 17 | + id="Include suffix match", |
| 18 | + ), |
| 19 | + pytest.param( |
| 20 | + "MyClass", |
| 21 | + {"include_suffixes": ["Client", "Service"]}, |
| 22 | + False, |
| 23 | + id="Include suffix no match", |
| 24 | + ), |
| 25 | + pytest.param( |
| 26 | + "MyBase", |
| 27 | + {"exclude_suffixes": ["Base", "Util"]}, |
| 28 | + False, |
| 29 | + id="Exclude suffix match", |
| 30 | + ), |
| 31 | + pytest.param( |
| 32 | + "MyClass", |
| 33 | + {"exclude_suffixes": ["Base", "Util"]}, |
| 34 | + True, |
| 35 | + id="Exclude suffix no match", |
| 36 | + ), |
| 37 | + pytest.param( |
| 38 | + "DatasetClient", |
| 39 | + {"include_suffixes": ["Client"], "exclude_suffixes": ["BaseClient"]}, |
| 40 | + True, |
| 41 | + id="Mix include/exclude match", |
| 42 | + ), |
| 43 | + pytest.param( |
| 44 | + "BaseClient", |
| 45 | + {"include_suffixes": ["Client"], "exclude_suffixes": ["BaseClient"]}, |
| 46 | + False, |
| 47 | + id="Mix include/exclude no match", |
| 48 | + ), |
| 49 | + pytest.param( |
| 50 | + "MyClass", |
| 51 | + {"include_suffixes": [], "exclude_suffixes": []}, |
| 52 | + True, |
| 53 | + id="Empty filters", |
| 54 | + ), |
| 55 | + ], |
| 56 | +) |
| 57 | +def test_should_include_class(class_name, filters, expected): |
| 58 | + assert _should_include_class(class_name, filters) is expected |
| 59 | + |
| 60 | + |
| 61 | +# Tests for _should_include_method |
| 62 | +@pytest.mark.parametrize( |
| 63 | + "method_name, filters, expected", |
| 64 | + [ |
| 65 | + pytest.param("my_method", {}, True, id="No filters"), |
| 66 | + pytest.param( |
| 67 | + "get_dataset", |
| 68 | + {"include_prefixes": ["get_", "list_"]}, |
| 69 | + True, |
| 70 | + id="Include prefix match (get)", |
| 71 | + ), |
| 72 | + pytest.param( |
| 73 | + "list_jobs", |
| 74 | + {"include_prefixes": ["get_", "list_"]}, |
| 75 | + True, |
| 76 | + id="Include prefix match (list)", |
| 77 | + ), |
| 78 | + pytest.param( |
| 79 | + "create_dataset", |
| 80 | + {"include_prefixes": ["get_", "list_"]}, |
| 81 | + False, |
| 82 | + id="Include prefix no match", |
| 83 | + ), |
| 84 | + pytest.param( |
| 85 | + "_private_method", |
| 86 | + {"exclude_prefixes": ["_", "internal_"]}, |
| 87 | + False, |
| 88 | + id="Exclude prefix match (private)", |
| 89 | + ), |
| 90 | + pytest.param( |
| 91 | + "internal_helper", |
| 92 | + {"exclude_prefixes": ["_", "internal_"]}, |
| 93 | + False, |
| 94 | + id="Exclude prefix match (internal)", |
| 95 | + ), |
| 96 | + pytest.param( |
| 97 | + "get_dataset", |
| 98 | + {"exclude_prefixes": ["_", "internal_"]}, |
| 99 | + True, |
| 100 | + id="Exclude prefix no match", |
| 101 | + ), |
| 102 | + pytest.param( |
| 103 | + "get_dataset", |
| 104 | + {"include_prefixes": ["get_"], "exclude_prefixes": ["get_internal_"]}, |
| 105 | + True, |
| 106 | + id="Mix include/exclude match", |
| 107 | + ), |
| 108 | + pytest.param( |
| 109 | + "get_internal_status", |
| 110 | + {"include_prefixes": ["get_"], "exclude_prefixes": ["get_internal_"]}, |
| 111 | + False, |
| 112 | + id="Mix include/exclude no match (exclude wins)", |
| 113 | + ), |
| 114 | + pytest.param( |
| 115 | + "list_datasets", |
| 116 | + {"include_prefixes": ["get_"], "exclude_prefixes": ["get_internal_"]}, |
| 117 | + False, |
| 118 | + id="Mix include/exclude no match (include fails)", |
| 119 | + ), |
| 120 | + pytest.param( |
| 121 | + "my_method", |
| 122 | + {"include_prefixes": [], "exclude_prefixes": []}, |
| 123 | + True, |
| 124 | + id="Empty filters", |
| 125 | + ), |
| 126 | + ], |
| 127 | +) |
| 128 | +def test_should_include_method(method_name, filters, expected): |
| 129 | + assert _should_include_method(method_name, filters) is expected |
0 commit comments