|
99 | 99 | * `@count PATH XPATH COUNT' checks for the occurrence of given XPath
|
100 | 100 | in the given file. The number of occurrences must match the given count.
|
101 | 101 |
|
| 102 | +* `@has-dir PATH` checks for the existence of the given directory. |
| 103 | +
|
102 | 104 | All conditions can be negated with `!`. `@!has foo/type.NoSuch.html`
|
103 | 105 | checks if the given file does not exist, for example.
|
104 | 106 |
|
@@ -308,6 +310,12 @@ def get_tree(self, path):
|
308 | 310 | self.trees[path] = tree
|
309 | 311 | return self.trees[path]
|
310 | 312 |
|
| 313 | + def get_dir(self, path): |
| 314 | + path = self.resolve_path(path) |
| 315 | + abspath = os.path.join(self.root, path) |
| 316 | + if not(os.path.exists(abspath) and os.path.isdir(abspath)): |
| 317 | + raise FailedCheck('Directory does not exist {!r}'.format(path)) |
| 318 | + |
311 | 319 |
|
312 | 320 | def check_string(data, pat, regexp):
|
313 | 321 | if not pat:
|
@@ -407,6 +415,16 @@ def check_command(c, cache):
|
407 | 415 | ret = expected == found
|
408 | 416 | else:
|
409 | 417 | raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
|
| 418 | + elif c.cmd == 'has-dir': # has-dir test |
| 419 | + if len(c.args) == 1: # @has-dir <path> = has-dir test |
| 420 | + try: |
| 421 | + cache.get_dir(c.args[0]) |
| 422 | + ret = True |
| 423 | + except FailedCheck as err: |
| 424 | + cerr = str(err) |
| 425 | + ret = False |
| 426 | + else: |
| 427 | + raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd)) |
410 | 428 | elif c.cmd == 'valid-html':
|
411 | 429 | raise InvalidCheck('Unimplemented @valid-html')
|
412 | 430 |
|
|
0 commit comments