Skip to content

Commit

Permalink
Update Gitignore and Pyproject.toml, and fix type checking in grassho…
Browse files Browse the repository at this point in the history
…pper library
  • Loading branch information
jmfiola committed Feb 27, 2024
1 parent 188d74d commit 6ea3e57
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ __pycache__
# don't include log files or anything else generated by running
*.log
.coverage
coverage.*
coverage.*
reports/junit_test_results.xml
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ line-length = 88

# Adds Pyflakes, Mccabe, Pydocstyle, etc. run `ruff linter` to see all available linters
extend-select = ["F", "C90", "I", "N", "ICN"]
ignore = [ "N801", "N803", "N806", "N815", "N818"]
ignore = [ "N801", "N803", "N806", "N815", "N818", "E721"]

# Allows a single underscore to be an unused variable
dummy-variable-rgx = "^_$"
Expand Down
6 changes: 3 additions & 3 deletions src/grasshopper/lib/configuration/gh_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
def typecast_dict(value):
"""Ensure that value is a dict (supports json strings) or log a warning."""
new_value = value
if isinstance(value, str):
if type(value) == str:
new_value = json.loads(value)
elif not isinstance(value, dict):
elif type(value) != dict:
logger.warning(
f"Configuration value [{value}] of type [{type(value)}] not able to be "
f"cast to dictionary."
Expand All @@ -40,7 +40,7 @@ def typecast_float(value):

def typecast_bool(value):
"""Ensure value is a bool or raise an error."""
if isinstance(value, str):
if type(value) == str:
new_value = value.lower() in ["true"]
else:
new_value = bool(value)
Expand Down
6 changes: 3 additions & 3 deletions src/grasshopper/lib/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def env_var_prefix_key(request):
prefix = "GH_"
try:
prefix = request.getfixturevalue("configuration_prefix_key")
if isinstance(prefix, str) or (isinstance(prefix, str) and len(prefix) == 0):
if type(prefix) != str or (type(prefix) == str and len(prefix) == 0):
logger.warning(
f"CONFIG FIXTURE: Fixture configuration_prefix_key may only be a non "
f"zero length str, returned value {prefix}, ignoring value."
Expand Down Expand Up @@ -585,10 +585,10 @@ def fetch_value_from_multiple_sources(sources, key):
def type_check_list_of_strs(list_of_strs):
"""Return True if list of strings or [], false if anything else."""
check_passed = False
if isinstance(list_of_strs, list):
if type(list_of_strs) == (list):
all_strs = True
for s in list_of_strs:
all_strs = all_strs and isinstance(s, str)
all_strs = all_strs and type(s) == str
check_passed = all_strs
return check_passed

Expand Down
10 changes: 6 additions & 4 deletions src/grasshopper/lib/util/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ def flush_check_to_dbs(self, check_name: str, check_passed: bool, extra_tags: di

@staticmethod
def _append_trend_data(environment):
if hasattr(environment.stats, "trends") and isinstance(
environment.stats.trends, dict
if (
hasattr(environment.stats, "trends")
and type(environment.stats.trends) is dict
):
for trend_name, trend_values in environment.stats.trends.items():
for threshold_object in trend_values.get("thresholds", []):
Expand All @@ -111,8 +112,9 @@ def _append_trend_data(environment):

@staticmethod
def _append_checks_data(environment):
if hasattr(environment.stats, "checks") and isinstance(
environment.stats.checks, dict
if (
hasattr(environment.stats, "checks")
and type(environment.stats.checks) is dict
):
# mark all checks as passed or failed based on multiple criteria
for check_key, check_item in environment.stats.checks.items():
Expand Down
2 changes: 1 addition & 1 deletion src/grasshopper/lib/util/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class Customstages(Stages): # noqa E501
def __init__(self, *args, **kwargs):
try:
stages = kwargs.get("stages")
if isinstance(stages, str):
if type(stages) == str:
stages = json.loads(stages)
self.stages = stages
except TypeError:
Expand Down
2 changes: 1 addition & 1 deletion src/grasshopper/lib/util/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def check(
"warning_threshold": flexible_warning,
}

if hasattr(env.stats, "checks") and isinstance(env.stats.checks, dict):
if hasattr(env.stats, "checks") and type(env.stats.checks) is dict:
if check_name not in env.stats.checks.keys():
env.stats.checks[check_name] = check_object
else:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def message_was_not_logged(

def make_re(potential_re):
"""Convert a string to a compiled re, otherwise return the value unaltered."""
if isinstance(potential_re, str):
if type(potential_re) == str:
potential_re = re.compile(potential_re, re.IGNORECASE)
return potential_re

Expand Down Expand Up @@ -210,7 +210,7 @@ def convert_dict_to_list(target_messages):
therefore only one message dict) less wordy and easier.
"""
if isinstance(target_messages, dict):
if type(target_messages) == dict:
target_messages = [target_messages]

return target_messages

0 comments on commit 6ea3e57

Please sign in to comment.