Skip to content

Commit

Permalink
Use pre-commit run black to fix the black linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
takirala committed Aug 8, 2018
1 parent b887312 commit 9f34b2f
Show file tree
Hide file tree
Showing 133 changed files with 7,046 additions and 6,268 deletions.
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Expand Up @@ -3,19 +3,16 @@ repos:
rev: stable
hooks:
- id: black
always_run: true
args: [--check]
language_version: python3
- id: black
always_run: true
name: black-format
language_version: python3
stages: [manual]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0
hooks:
- id: flake8
always_run: true
- repo: local
hooks:
- id: pylint
Expand All @@ -24,4 +21,3 @@ repos:
args: [-E, -j4]
language: system
types: [python]
always_run: true
2 changes: 1 addition & 1 deletion __init__.py
Expand Up @@ -3,4 +3,4 @@

# Add /testing/ to PYTHONPATH:
this_file_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.normpath(os.path.join(this_file_dir, 'testing')))
sys.path.append(os.path.normpath(os.path.join(this_file_dir, "testing")))
58 changes: 35 additions & 23 deletions conftest.py
Expand Up @@ -15,10 +15,11 @@
import sdk_utils
import teamcity

log_level = os.getenv('TEST_LOG_LEVEL', 'INFO').upper()
log_levels = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL', 'EXCEPTION')
assert log_level in log_levels, \
'{} is not a valid log level. Use one of: {}'.format(log_level, ', '.join(log_levels))
log_level = os.getenv("TEST_LOG_LEVEL", "INFO").upper()
log_levels = ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "EXCEPTION")
assert log_level in log_levels, "{} is not a valid log level. Use one of: {}".format(
log_level, ", ".join(log_levels)
)
# write everything to stdout due to the following circumstances:
# - shakedown uses print() aka stdout
# - teamcity splits out stdout vs stderr into separate outputs, we'd want them combined
Expand All @@ -30,18 +31,20 @@
rootlog.removeHandler(h)
h.close()
logging.basicConfig(
format='[%(asctime)s|%(name)s-%(funcName)s(%(lineno)d)|%(levelname)s]: %(message)s',
format="[%(asctime)s|%(name)s-%(funcName)s(%(lineno)d)|%(levelname)s]: %(message)s",
level=log_level,
stream=sys.stdout)
stream=sys.stdout,
)

# reduce excessive DEBUG/INFO noise produced by some underlying libraries:
for noise_source in [
'dcos.http',
'dcos.marathon',
'dcos.util',
'paramiko.transport',
'urllib3.connectionpool']:
logging.getLogger(noise_source).setLevel('WARNING')
"dcos.http",
"dcos.marathon",
"dcos.util",
"paramiko.transport",
"urllib3.connectionpool",
]:
logging.getLogger(noise_source).setLevel("WARNING")

log = logging.getLogger(__name__)

Expand All @@ -53,23 +56,24 @@ def is_env_var_set(key: str, default: str) -> bool:
# The following environment variable allows for log collection to be turned off.
# This is useful, for example in testing.
INTEGRATION_TEST_LOG_COLLECTION = is_env_var_set(
'INTEGRATION_TEST_LOG_COLLECTION', default=str(True))
"INTEGRATION_TEST_LOG_COLLECTION", default=str(True)
)


@pytest.fixture(scope='session', autouse=True)
@pytest.fixture(scope="session", autouse=True)
def configure_universe(tmpdir_factory):
if is_env_var_set('PACKAGE_REGISTRY_ENABLED', default=''):
if is_env_var_set("PACKAGE_REGISTRY_ENABLED", default=""):
yield from sdk_package_registry.package_registry_session(tmpdir_factory)
else:
yield from sdk_repository.universe_session()


@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item: pytest.Item, call): # _pytest.runner.CallInfo
'''Hook to run after every test, before any other post-test hooks.
"""Hook to run after every test, before any other post-test hooks.
See also: https://docs.pytest.org/en/latest/example/simple.html\
#making-test-result-information-available-in-fixtures
'''
"""

# Execute all other hooks to obtain the report object.
outcome = yield
Expand All @@ -83,25 +87,33 @@ def pytest_runtest_makereport(item: pytest.Item, call): # _pytest.runner.CallIn


def pytest_runtest_teardown(item: pytest.Item):
'''Hook to run after every test.'''
"""Hook to run after every test."""
# Inject footer at end of test, may be followed by additional teardown.
# Don't do this when running in teamcity, where it's redundant.
if not teamcity.is_running_under_teamcity():
print('''
print(
"""
==========
======= END: {}::{}
=========='''.format(sdk_diag.get_test_suite_name(item), item.name))
==========""".format(
sdk_diag.get_test_suite_name(item), item.name
)
)


def pytest_runtest_setup(item: pytest.Item):
'''Hook to run before every test.'''
"""Hook to run before every test."""
# Inject header at start of test, following automatic "path/to/test_file.py::test_name":
# Don't do this when running in teamcity, where it's redundant.
if not teamcity.is_running_under_teamcity():
print('''
print(
"""
==========
======= START: {}::{}
=========='''.format(sdk_diag.get_test_suite_name(item), item.name))
==========""".format(
sdk_diag.get_test_suite_name(item), item.name
)
)

if INTEGRATION_TEST_LOG_COLLECTION:
sdk_diag.handle_test_setup(item)
Expand Down

0 comments on commit 9f34b2f

Please sign in to comment.