(module, test_path)
| 410 | |
| 411 | # [XX] Normalize with respect to os.path.pardir? |
| 412 | def _module_relative_path(module, test_path): |
| 413 | if not inspect.ismodule(module): |
| 414 | raise TypeError('Expected a module: %r' % module) |
| 415 | if test_path.startswith('/'): |
| 416 | raise ValueError('Module-relative files may not have absolute paths') |
| 417 | |
| 418 | # Normalize the path. On Windows, replace "/" with "\". |
| 419 | test_path = os.path.join(*(test_path.split('/'))) |
| 420 | |
| 421 | # Find the base directory for the path. |
| 422 | if hasattr(module, '__file__'): |
| 423 | # A normal module/package |
| 424 | basedir = os.path.split(module.__file__)[0] |
| 425 | elif module.__name__ == '__main__': |
| 426 | # An interactive session. |
| 427 | if len(sys.argv)>0 and sys.argv[0] != '': |
| 428 | basedir = os.path.split(sys.argv[0])[0] |
| 429 | else: |
| 430 | basedir = os.curdir |
| 431 | else: |
| 432 | if hasattr(module, '__path__'): |
| 433 | for directory in module.__path__: |
| 434 | fullpath = os.path.join(directory, test_path) |
| 435 | if os.path.exists(fullpath): |
| 436 | return fullpath |
| 437 | |
| 438 | # A module w/o __file__ (this includes builtins) |
| 439 | raise ValueError("Can't resolve paths relative to the module " |
| 440 | "%r (it has no __file__)" |
| 441 | % module.__name__) |
| 442 | |
| 443 | # Combine the base directory and the test path. |
| 444 | return os.path.join(basedir, test_path) |
| 445 | |
| 446 | ###################################################################### |
| 447 | ## 2. Example & DocTest |
no test coverage detected
searching dependent graphs…