Skip to content

Commit b205457

Browse files
committed
---
yaml --- r: 187832 b: refs/heads/tmp c: 5e1d4ff h: refs/heads/master v: v3
1 parent 2efa24e commit b205457

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 522d09dfecbeca1595f25ac58c6d0178bbd21d7d
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: f7aafcced8d7374ddbe50a509cb0bcec959254c4
37+
refs/heads/tmp: 5e1d4fffff1516758f43b22b2e89327e5ec0918c
3838
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/tmp/src/etc/htmldocck.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
highlights for example. If you want to simply check the presence of
9797
given node or attribute, use an empty string (`""`) as a `PATTERN`.
9898
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+
99102
All conditions can be negated with `!`. `@!has foo/type.NoSuch.html`
100103
checks if the given file does not exist, for example.
101104
@@ -333,6 +336,11 @@ def check_tree_text(tree, path, pat, regexp):
333336
return ret
334337

335338

339+
def check_tree_count(tree, path, count):
340+
path = normalize_xpath(path)
341+
return len(tree.findall(path)) == count
342+
343+
336344
def check(target, commands):
337345
cache = CachedFiles(target)
338346
for c in commands:
@@ -360,6 +368,13 @@ def check(target, commands):
360368
raise RuntimeError('Invalid number of @{} arguments \
361369
at line {}'.format(c.cmd, c.lineno))
362370

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+
363378
elif c.cmd == 'valid-html':
364379
raise RuntimeError('Unimplemented @valid-html at line {}'.format(c.lineno))
365380

0 commit comments

Comments
 (0)