|
| 1 | +"""Tests for remaining WOQL edge cases to increase coverage.""" |
| 2 | +import pytest |
| 3 | +from terminusdb_client.woqlquery.woql_query import WOQLQuery, Var |
| 4 | + |
| 5 | + |
| 6 | +class TestWOQLDistinctEdgeCases: |
| 7 | + """Test distinct operation edge cases.""" |
| 8 | + |
| 9 | + def test_distinct_with_existing_cursor(self): |
| 10 | + """Test distinct wraps cursor with and when cursor exists.""" |
| 11 | + query = WOQLQuery() |
| 12 | + # Set up existing cursor |
| 13 | + query._cursor["@type"] = "Triple" |
| 14 | + query._cursor["subject"] = "v:X" |
| 15 | + |
| 16 | + # This should trigger line 819 - wrap cursor with and |
| 17 | + result = query.distinct("v:X", "v:Y") |
| 18 | + |
| 19 | + assert result is query |
| 20 | + |
| 21 | + def test_distinct_empty_list_handling(self): |
| 22 | + """Test distinct with empty list.""" |
| 23 | + query = WOQLQuery() |
| 24 | + # This tests line 822 validation (similar to select bug) |
| 25 | + result = query.distinct() |
| 26 | + |
| 27 | + assert result is query |
| 28 | + |
| 29 | + |
| 30 | +class TestWOQLStartEdgeCase: |
| 31 | + """Test start operation edge case.""" |
| 32 | + |
| 33 | + def test_start_args_introspection(self): |
| 34 | + """Test start returns args list when called with 'args'.""" |
| 35 | + result = WOQLQuery().start("args") |
| 36 | + |
| 37 | + assert result == ["start", "query"] |
| 38 | + |
| 39 | + |
| 40 | +class TestWOQLCommentEdgeCase: |
| 41 | + """Test comment operation edge case.""" |
| 42 | + |
| 43 | + def test_comment_args_introspection(self): |
| 44 | + """Test comment returns args list when called with 'args'.""" |
| 45 | + result = WOQLQuery().comment("args") |
| 46 | + |
| 47 | + assert result == ["comment", "query"] |
| 48 | + |
| 49 | + |
| 50 | +class TestWOQLMathOperationEdgeCases: |
| 51 | + """Test math operation edge cases for arithmetic operations.""" |
| 52 | + |
| 53 | + def test_plus_args_introspection(self): |
| 54 | + """Test plus returns args list when called with 'args'.""" |
| 55 | + result = WOQLQuery().plus("args", 5) |
| 56 | + |
| 57 | + assert result == ["left", "right"] |
| 58 | + |
| 59 | + def test_minus_args_introspection(self): |
| 60 | + """Test minus returns args list when called with 'args'.""" |
| 61 | + result = WOQLQuery().minus("args", 5) |
| 62 | + |
| 63 | + assert result == ["left", "right"] |
| 64 | + |
| 65 | + def test_times_args_introspection(self): |
| 66 | + """Test times returns args list when called with 'args'.""" |
| 67 | + result = WOQLQuery().times("args", 5) |
| 68 | + |
| 69 | + assert result == ["left", "right"] |
| 70 | + |
| 71 | + def test_divide_args_introspection(self): |
| 72 | + """Test divide returns args list when called with 'args'.""" |
| 73 | + result = WOQLQuery().divide("args", 5) |
| 74 | + |
| 75 | + assert result == ["left", "right"] |
| 76 | + |
| 77 | + def test_div_args_introspection(self): |
| 78 | + """Test div returns args list when called with 'args'.""" |
| 79 | + result = WOQLQuery().div("args", 5) |
| 80 | + |
| 81 | + assert result == ["left", "right"] |
| 82 | + |
| 83 | + |
| 84 | +class TestWOQLComparisonOperationEdgeCases: |
| 85 | + """Test comparison operation edge cases.""" |
| 86 | + |
| 87 | + def test_greater_args_introspection(self): |
| 88 | + """Test greater returns args list when called with 'args'.""" |
| 89 | + result = WOQLQuery().greater("args", 5) |
| 90 | + |
| 91 | + assert result == ["left", "right"] |
| 92 | + |
| 93 | + def test_less_args_introspection(self): |
| 94 | + """Test less returns args list when called with 'args'.""" |
| 95 | + result = WOQLQuery().less("args", 5) |
| 96 | + |
| 97 | + assert result == ["left", "right"] |
| 98 | + |
| 99 | + # Note: gte and lte methods don't exist in WOQLQuery |
| 100 | + # Lines 2895, 2897 are not covered by args introspection |
| 101 | + |
| 102 | + |
| 103 | +class TestWOQLLogicalOperationEdgeCases: |
| 104 | + """Test logical operation edge cases.""" |
| 105 | + |
| 106 | + def test_woql_not_args_introspection(self): |
| 107 | + """Test woql_not returns args list when called with 'args'.""" |
| 108 | + result = WOQLQuery().woql_not("args") |
| 109 | + |
| 110 | + assert result == ["query"] |
| 111 | + |
| 112 | + def test_once_args_introspection(self): |
| 113 | + """Test once returns args list when called with 'args'.""" |
| 114 | + result = WOQLQuery().once("args") |
| 115 | + |
| 116 | + assert result == ["query"] |
| 117 | + |
| 118 | + def test_immediately_args_introspection(self): |
| 119 | + """Test immediately returns args list when called with 'args'.""" |
| 120 | + result = WOQLQuery().immediately("args") |
| 121 | + |
| 122 | + assert result == ["query"] |
| 123 | + |
| 124 | + def test_count_args_introspection(self): |
| 125 | + """Test count returns args list when called with 'args'.""" |
| 126 | + result = WOQLQuery().count("args") |
| 127 | + |
| 128 | + assert result == ["count", "query"] |
| 129 | + |
| 130 | + def test_cast_args_introspection(self): |
| 131 | + """Test cast returns args list when called with 'args'.""" |
| 132 | + result = WOQLQuery().cast("args", "xsd:string", "v:Result") |
| 133 | + |
| 134 | + assert result == ["value", "type", "result"] |
| 135 | + |
| 136 | + |
| 137 | +class TestWOQLTypeOperationEdgeCases: |
| 138 | + """Test type operation edge cases.""" |
| 139 | + |
| 140 | + def test_type_of_args_introspection(self): |
| 141 | + """Test type_of returns args list when called with 'args'.""" |
| 142 | + result = WOQLQuery().type_of("args", "v:Type") |
| 143 | + |
| 144 | + assert result == ["value", "type"] |
| 145 | + |
| 146 | + def test_order_by_args_introspection(self): |
| 147 | + """Test order_by returns args list when called with 'args'.""" |
| 148 | + result = WOQLQuery().order_by("args") |
| 149 | + |
| 150 | + assert isinstance(result, WOQLQuery) |
| 151 | + |
| 152 | + def test_group_by_args_introspection(self): |
| 153 | + """Test group_by returns args list when called with 'args'.""" |
| 154 | + result = WOQLQuery().group_by("args", "v:Template", "v:Result") |
| 155 | + |
| 156 | + assert result == ["group_by", "template", "grouped", "query"] |
| 157 | + |
| 158 | + def test_length_args_introspection(self): |
| 159 | + """Test length returns args list when called with 'args'.""" |
| 160 | + result = WOQLQuery().length("args", "v:Length") |
| 161 | + |
| 162 | + assert result == ["list", "length"] |
| 163 | + |
| 164 | + |
| 165 | +class TestWOQLStringOperationEdgeCases: |
| 166 | + """Test string operation edge cases.""" |
| 167 | + |
| 168 | + def test_upper_args_introspection(self): |
| 169 | + """Test upper returns args list when called with 'args'.""" |
| 170 | + result = WOQLQuery().upper("args", "v:Upper") |
| 171 | + |
| 172 | + assert result == ["left", "right"] |
| 173 | + |
| 174 | + def test_lower_args_introspection(self): |
| 175 | + """Test lower returns args list when called with 'args'.""" |
| 176 | + result = WOQLQuery().lower("args", "v:Lower") |
| 177 | + |
| 178 | + assert result == ["left", "right"] |
| 179 | + |
| 180 | + def test_pad_args_introspection(self): |
| 181 | + """Test pad returns args list when called with 'args'.""" |
| 182 | + result = WOQLQuery().pad("args", "X", 10, "v:Padded") |
| 183 | + |
| 184 | + assert result == ["string", "char", "times", "result"] |
| 185 | + |
| 186 | + |
| 187 | +class TestWOQLRegexOperationEdgeCases: |
| 188 | + """Test regex operation edge cases.""" |
| 189 | + |
| 190 | + def test_split_args_introspection(self): |
| 191 | + """Test split returns args list when called with 'args'.""" |
| 192 | + result = WOQLQuery().split("args", ",", "v:List") |
| 193 | + |
| 194 | + assert result == ["string", "pattern", "list"] |
| 195 | + |
| 196 | + def test_regexp_args_introspection(self): |
| 197 | + """Test regexp returns args list when called with 'args'.""" |
| 198 | + result = WOQLQuery().regexp("args", "[0-9]+", "v:Match") |
| 199 | + |
| 200 | + assert result == ["pattern", "string", "result"] |
| 201 | + |
| 202 | + def test_like_args_introspection(self): |
| 203 | + """Test like returns args list when called with 'args'.""" |
| 204 | + result = WOQLQuery().like("args", "test%", 0.8) |
| 205 | + |
| 206 | + assert result == ["left", "right", "similarity"] |
| 207 | + |
| 208 | + |
| 209 | +class TestWOQLSubstringOperationEdgeCases: |
| 210 | + """Test substring operation edge cases.""" |
| 211 | + |
| 212 | + def test_substring_args_introspection(self): |
| 213 | + """Test substring returns args list when called with 'args'.""" |
| 214 | + result = WOQLQuery().substring("args", 0, 5, "v:Result") |
| 215 | + |
| 216 | + assert result == ["string", "before", "length", "after", "substring"] |
| 217 | + |
| 218 | + def test_concat_args_already_tested(self): |
| 219 | + """Test concat args introspection.""" |
| 220 | + # This is already tested in test_woql_set_operations.py |
| 221 | + # but included here for completeness |
| 222 | + result = WOQLQuery().concat("args", "v:Result") |
| 223 | + |
| 224 | + assert result == ["list", "concatenated"] |
| 225 | + |
| 226 | + |
| 227 | +class TestWOQLTrimOperationEdgeCase: |
| 228 | + """Test trim operation edge case.""" |
| 229 | + |
| 230 | + def test_trim_args_introspection(self): |
| 231 | + """Test trim returns args list when called with 'args'.""" |
| 232 | + result = WOQLQuery().trim("args", "v:Trimmed") |
| 233 | + |
| 234 | + assert result == ["untrimmed", "trimmed"] |
| 235 | + |
| 236 | + |
| 237 | +class TestWOQLVariousOperationEdgeCases: |
| 238 | + """Test various operation edge cases.""" |
| 239 | + |
| 240 | + def test_limit_args_introspection(self): |
| 241 | + """Test limit returns args list when called with 'args'.""" |
| 242 | + result = WOQLQuery().limit("args") |
| 243 | + |
| 244 | + assert result == ["limit", "query"] |
| 245 | + |
| 246 | + def test_get_args_introspection(self): |
| 247 | + """Test get returns args list when called with 'args'.""" |
| 248 | + result = WOQLQuery().get("args") |
| 249 | + |
| 250 | + assert result == ["columns", "resource"] |
| 251 | + |
| 252 | + def test_put_args_introspection(self): |
| 253 | + """Test put returns args list when called with 'args'.""" |
| 254 | + result = WOQLQuery().put("args", WOQLQuery()) |
| 255 | + |
| 256 | + assert result == ["columns", "query", "resource"] |
| 257 | + |
| 258 | + def test_file_args_introspection(self): |
| 259 | + """Test file returns args list when called with 'args'.""" |
| 260 | + result = WOQLQuery().file("args") |
| 261 | + |
| 262 | + assert result == ["source", "format"] |
| 263 | + |
| 264 | + def test_remote_args_introspection(self): |
| 265 | + """Test remote returns args list when called with 'args'.""" |
| 266 | + result = WOQLQuery().remote("args") |
| 267 | + |
| 268 | + assert result == ["source", "format", "options"] |
| 269 | + |
| 270 | + |
| 271 | +class TestWOQLAsMethodEdgeCases: |
| 272 | + """Test as() method edge cases.""" |
| 273 | + |
| 274 | + def test_as_with_two_element_list(self): |
| 275 | + """Test as() with two-element list.""" |
| 276 | + query = WOQLQuery() |
| 277 | + result = query.woql_as([["v:X", "name"]]) |
| 278 | + |
| 279 | + assert result is query |
| 280 | + assert len(query._query) >= 1 |
| 281 | + |
| 282 | + def test_as_with_three_element_list_with_type(self): |
| 283 | + """Test as() with three-element list including type.""" |
| 284 | + query = WOQLQuery() |
| 285 | + result = query.woql_as([["v:X", "name", "xsd:string"]]) |
| 286 | + |
| 287 | + assert result is query |
| 288 | + assert len(query._query) >= 1 |
| 289 | + |
| 290 | + def test_as_with_xsd_prefix_in_second_arg(self): |
| 291 | + """Test as() with xsd: prefix in second argument.""" |
| 292 | + query = WOQLQuery() |
| 293 | + result = query.woql_as(0, "v:Value", "xsd:string") |
| 294 | + |
| 295 | + assert result is query |
| 296 | + assert len(query._query) >= 1 |
| 297 | + |
| 298 | + def test_as_with_object_to_dict(self): |
| 299 | + """Test as() with object having to_dict method.""" |
| 300 | + query = WOQLQuery() |
| 301 | + var = Var("X") |
| 302 | + result = query.woql_as(var) |
| 303 | + |
| 304 | + assert result is query |
| 305 | + assert len(query._query) >= 1 |
| 306 | + |
| 307 | + |
| 308 | +class TestWOQLMethodEdgeCases: |
| 309 | + """Test various method edge cases.""" |
| 310 | + |
| 311 | + def test_woql_or_args_introspection(self): |
| 312 | + """Test woql_or returns args list when called with 'args'.""" |
| 313 | + result = WOQLQuery().woql_or("args") |
| 314 | + |
| 315 | + assert result == ["or"] |
| 316 | + |
| 317 | + # Note: 'from' is a reserved keyword in Python, method may not have args introspection |
| 318 | + |
| 319 | + def test_into_args_introspection(self): |
| 320 | + """Test into returns args list when called with 'args'.""" |
| 321 | + result = WOQLQuery().into("args", WOQLQuery()) |
| 322 | + |
| 323 | + assert result == ["graph", "query"] |
| 324 | + |
| 325 | + def test_using_args_introspection(self): |
| 326 | + """Test using returns args list when called with 'args'.""" |
| 327 | + result = WOQLQuery().using("args") |
| 328 | + |
| 329 | + assert result == ["collection", "query"] |
0 commit comments