Loads content from file_path if file_path's extension is one of allowed ones (See ALLOWED_EXTS). Throws UnsupportedMetaException on disallowed filetypes. :param file_path: Absolute path to the file to load content from. :type file_path: ``str`` :rtype: ``dict``
(file_path)
| 34 | |
| 35 | |
| 36 | def load_content(file_path): |
| 37 | """ |
| 38 | Loads content from file_path if file_path's extension |
| 39 | is one of allowed ones (See ALLOWED_EXTS). |
| 40 | Throws UnsupportedMetaException on disallowed filetypes. |
| 41 | :param file_path: Absolute path to the file to load content from. |
| 42 | :type file_path: ``str`` |
| 43 | :rtype: ``dict`` |
| 44 | """ |
| 45 | file_name, file_ext = os.path.splitext(file_path) |
| 46 | |
| 47 | if file_ext not in ALLOWED_EXTS: |
| 48 | raise Exception( |
| 49 | "Unsupported meta type %s, file %s. Allowed: %s" |
| 50 | % (file_ext, file_path, ALLOWED_EXTS) |
| 51 | ) |
| 52 | |
| 53 | parser_func = PARSER_FUNCS.get(file_ext, None) |
| 54 | |
| 55 | with open(file_path, "r") as fd: |
| 56 | return parser_func(fd) if parser_func else fd.read() |
| 57 | |
| 58 | |
| 59 | def load_fixtures(fixtures_dict=None): |
no test coverage detected