(path)
| 327 | } |
| 328 | |
| 329 | def PresubmitCheck(path): |
| 330 | with open(path) as f: |
| 331 | contents = ReadContent(f.read()) |
| 332 | basename = os.path.basename(os.path.dirname(path)) |
| 333 | root_prefix = basename + "/" |
| 334 | test_extensions = JS_TEST_EXTENSIONS.get( |
| 335 | basename, DEFAULT_JS_TEST_EXTENSIONS) |
| 336 | status = {"success": True} |
| 337 | def _assert(check, message): # Like "assert", but doesn't throw. |
| 338 | if not check: |
| 339 | print("%s: Error: %s" % (path, message)) |
| 340 | status["success"] = False |
| 341 | try: |
| 342 | for section in contents: |
| 343 | _assert(type(section) == list, "Section must be a list") |
| 344 | _assert(len(section) == 2, "Section list must have exactly 2 entries") |
| 345 | section = section[1] |
| 346 | _assert(type(section) == dict, |
| 347 | "Second entry of section must be a dictionary") |
| 348 | for rule in section: |
| 349 | _assert(type(rule) == str, "Rule key must be a string") |
| 350 | _assert(not rule.startswith(root_prefix), |
| 351 | "Suite name prefix must not be used in rule keys") |
| 352 | _assert(not rule.endswith('.js'), |
| 353 | ".js extension must not be used in rule keys.") |
| 354 | _assert('*' not in rule or (rule.count('*') == 1 and rule[-1] == '*'), |
| 355 | "Only the last character of a rule key can be a wildcard") |
| 356 | if basename in JS_TEST_PATHS and '*' not in rule: |
| 357 | def _any_exist(paths): |
| 358 | return any( |
| 359 | os.path.exists( |
| 360 | os.path.join( |
| 361 | os.path.dirname(path), *(paths + [rule + ext]))) |
| 362 | for ext in test_extensions) |
| 363 | _assert(any(_any_exist(paths) |
| 364 | for paths in JS_TEST_PATHS[basename]), |
| 365 | "missing file for %s test %s" % (basename, rule)) |
| 366 | return status["success"] |
| 367 | except Exception as e: |
| 368 | print(e) |
| 369 | return False |
nothing calls this directly
no test coverage detected