|
96 | 96 | highlights for example. If you want to simply check the presence of
|
97 | 97 | given node or attribute, use an empty string (`""`) as a `PATTERN`.
|
98 | 98 |
|
| 99 | +* `@count PATH XPATH COUNT' checks for the occurrence of given XPath |
| 100 | + in the given file. The number of occurrences must match the given count. |
| 101 | +
|
99 | 102 | All conditions can be negated with `!`. `@!has foo/type.NoSuch.html`
|
100 | 103 | checks if the given file does not exist, for example.
|
101 | 104 |
|
@@ -333,6 +336,11 @@ def check_tree_text(tree, path, pat, regexp):
|
333 | 336 | return ret
|
334 | 337 |
|
335 | 338 |
|
| 339 | +def check_tree_count(tree, path, count): |
| 340 | + path = normalize_xpath(path) |
| 341 | + return len(tree.findall(path)) == count |
| 342 | + |
| 343 | + |
336 | 344 | def check(target, commands):
|
337 | 345 | cache = CachedFiles(target)
|
338 | 346 | for c in commands:
|
@@ -360,6 +368,13 @@ def check(target, commands):
|
360 | 368 | raise RuntimeError('Invalid number of @{} arguments \
|
361 | 369 | at line {}'.format(c.cmd, c.lineno))
|
362 | 370 |
|
| 371 | + elif c.cmd == 'count': # count test |
| 372 | + if len(c.args) == 3: # @count <path> <pat> <count> = count test |
| 373 | + ret = check_tree_count(cache.get_tree(c.args[0]), c.args[1], int(c.args[2])) |
| 374 | + else: |
| 375 | + raise RuntimeError('Invalid number of @{} arguments \ |
| 376 | + at line {}'.format(c.cmd, c.lineno)) |
| 377 | + |
363 | 378 | elif c.cmd == 'valid-html':
|
364 | 379 | raise RuntimeError('Unimplemented @valid-html at line {}'.format(c.lineno))
|
365 | 380 |
|
|
0 commit comments