Skip to content

Commit

Permalink
test: caplog fix (#1665)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Sep 18, 2023
1 parent 2bda5be commit 2611f20
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
12 changes: 5 additions & 7 deletions tests/functional/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
from typing import Dict, Union

import pytest
Expand All @@ -24,12 +23,11 @@ def test_integer_deployment_addresses(networks):
)
def test_bad_value_in_deployments(ecosystems, networks, err_part, caplog, plugin_manager):
deployments = _create_deployments()
with caplog.at_level(logging.WARNING):
all_ecosystems = dict(plugin_manager.ecosystems)
ecosystem_dict = {e: all_ecosystems[e] for e in ecosystems if e in all_ecosystems}
DeploymentConfigCollection(deployments, ecosystem_dict, networks)
assert len(caplog.records) > 0, "Nothing was logged"
assert f"Invalid {err_part}" in caplog.records[0].message
all_ecosystems = dict(plugin_manager.ecosystems)
ecosystem_dict = {e: all_ecosystems[e] for e in ecosystems if e in all_ecosystems}
DeploymentConfigCollection(deployments, ecosystem_dict, networks)
assert len(caplog.records) > 0, "Nothing was logged"
assert f"Invalid {err_part}" in caplog.records[0].message


def _create_deployments(ecosystem_name: str = "ethereum", network_name: str = "local") -> Dict:
Expand Down
7 changes: 2 additions & 5 deletions tests/functional/test_query.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import time

import pandas as pd
Expand Down Expand Up @@ -88,13 +87,11 @@ def test_column_validation(eth_tester_provider, caplog):
expected = "Unrecognized field(s) 'numbr', must be one of 'number, timestamp'."
assert exc_info.value.args[-1] == expected

with caplog.at_level(logging.WARNING):
validate_and_expand_columns(["numbr", "timestamp"], Model)
validate_and_expand_columns(["numbr", "timestamp"], Model)

assert expected in caplog.records[-1].msg

with caplog.at_level(logging.WARNING):
validate_and_expand_columns(["number", "timestamp", "number"], Model)
validate_and_expand_columns(["number", "timestamp", "number"], Model)

assert "Duplicate fields in ['number', 'timestamp', 'number']" in caplog.records[-1].msg

Expand Down
5 changes: 3 additions & 2 deletions tests/integration/cli/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,15 @@ def test_compile_only_dependency(ape_cli, runner, project, clean_cache, caplog):
# Trigger actual dependency compilation
dependency = project.dependencies["dependency-in-project-only"]["local"]
_ = dependency.DependencyInProjectOnly

# Pop the log record off here so we can check the tail again below.
log_record = caplog.records.pop()
assert expected_log_message in log_record.message

# It should not need to compile again.
_ = dependency.DependencyInProjectOnly
if caplog.records:
log_record = caplog.records.pop()
assert expected_log_message not in log_record.message, "Compiled twice!"
assert expected_log_message not in caplog.records[-1].message, "Compiled twice!"

# Force a re-compile and trigger the dependency to compile via CLI
result = runner.invoke(
Expand Down

0 comments on commit 2611f20

Please sign in to comment.