diff options
author | Matt Clay <mclay@redhat.com> | 2020-02-04 11:21:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-04 11:21:53 -0800 |
commit | f4a80bb600510669801c5d5c0a250952748e99fd (patch) | |
tree | 83ce363b557a66453a9f2c9d0b84c589e09fc57a /test/lib/ansible_test/_internal/coverage/combine.py | |
parent | 994a6b0c5a7929051e5e2101004ef536ec47c0b3 (diff) | |
download | ansible-f4a80bb600510669801c5d5c0a250952748e99fd.tar.gz |
Code cleanup and refactoring in ansible-test. (#67063)
* Code cleanup in ansible-test.
* Split out encoding functions.
* Consoldate loading of JSON files.
* Split out disk IO functions.
* Simplify file access.
* Add functions for opening files.
* Replace open calls with appropriate functions.
* Expose more types from typing module.
* Support writing compact JSON.
* Add verbosity argument to display.warning.
* Add changelog entry.
* Update files overlooked during rebase.
* Use `io.open` instead of `open`.
* Fix file opening for imp.load_module.
* Remove use of `r+` mode to access files.
* Add missing import.
* Fix httptester on Python 2.x.
* Clarify changelog fragment.
* Consolidate imports. Remove extra newlines.
* Fix indirect imports.
Diffstat (limited to 'test/lib/ansible_test/_internal/coverage/combine.py')
-rw-r--r-- | test/lib/ansible_test/_internal/coverage/combine.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/test/lib/ansible_test/_internal/coverage/combine.py b/test/lib/ansible_test/_internal/coverage/combine.py index 9d6d82d2a7..a07a4dd6de 100644 --- a/test/lib/ansible_test/_internal/coverage/combine.py +++ b/test/lib/ansible_test/_internal/coverage/combine.py @@ -2,7 +2,6 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import json import os import re @@ -12,9 +11,13 @@ from ..target import ( walk_powershell_targets, ) +from ..io import ( + read_json_file, + read_text_file, +) + from ..util import ( display, - to_text, ) from ..util_common import ( @@ -191,8 +194,7 @@ def _command_coverage_combine_powershell(args): continue try: - with open(coverage_file, 'rb') as original_fd: - coverage_run = json.loads(to_text(original_fd.read(), errors='replace')) + coverage_run = read_json_file(coverage_file) except Exception as ex: # pylint: disable=locally-disabled, broad-except display.error(u'%s' % ex) continue @@ -275,8 +277,7 @@ def _get_coverage_targets(args, walk_func): for target in walk_func(include_symlinks=False): target_path = os.path.abspath(target.path) - with open(target_path, 'r') as target_fd: - target_lines = len(target_fd.read().splitlines()) + target_lines = len(read_text_file(target_path).splitlines()) sources.append((target_path, target_lines)) @@ -327,6 +328,7 @@ def get_coverage_group(args, coverage_file): """ parts = os.path.basename(coverage_file).split('=', 4) + # noinspection PyTypeChecker if len(parts) != 5 or not parts[4].startswith('coverage.'): return None |