Skip to content

Commit

Permalink
fix linting issues
Browse files Browse the repository at this point in the history
Project is now PEP8 compliant after running 'black' python code
formatter.
https://pypi.org/project/black
  • Loading branch information
vishalvvr committed Nov 8, 2023
1 parent d4c7a0c commit df1663b
Show file tree
Hide file tree
Showing 16 changed files with 267 additions and 217 deletions.
4 changes: 3 additions & 1 deletion core/opl/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ def data_stats(data):
data = [i for i in data if isinstance(i, datetime.datetime) or math.isfinite(i)]
count_strange = data_len_before - len(data)
if count_strange > 0:
logging.warning(f"There were {count_strange} NaN/Inf values in the data. Filtered them out.")
logging.warning(
f"There were {count_strange} NaN/Inf values in the data. Filtered them out."
)

non_zero_data = [i for i in data if i != 0]

Expand Down
22 changes: 18 additions & 4 deletions core/opl/status_data_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,11 @@ def _get_es_result_for_rp_result(session, args, run_id, result):
def _get_es_dashboard_result_for_run_id(session, args, run_id, test=None):
if test is not None:
response = _es_get_test(
session, args, ["result_id.keyword", "test.keyword"], [run_id, test], sort_by="date"
session,
args,
["result_id.keyword", "test.keyword"],
[run_id, test],
sort_by="date",
)
else:
response = _es_get_test(
Expand Down Expand Up @@ -466,7 +470,9 @@ def doit_rp_to_dashboard_new(args):
session, args, run_id
)
except requests.exceptions.HTTPError as e:
matching = "No mapping found for [date] in order to sort on" in e.response.text
matching = (
"No mapping found for [date] in order to sort on" in e.response.text
)
if e.response.status_code == 400 and matching:
logging.debug(
"Request failed, but I guess it was because index is still empty"
Expand Down Expand Up @@ -503,6 +509,7 @@ def doit_rp_to_dashboard_new(args):
)
print(f"Created result {run_id} in the dashboard with value {result}")


def _update_es_dashboard_result(session, args, es_id, result_string):
url = f"{args.es_server}/{args.es_index}/_doc/{es_id}/_update"
headers = {
Expand All @@ -526,6 +533,7 @@ def _update_es_dashboard_result(session, args, es_id, result_string):
f"Got back this: {json.dumps(response.json(), sort_keys=True, indent=4)}"
)


def doit_rp_to_dashboard_update(args):
assert args.es_server is not None
assert args.rp_host is not None
Expand Down Expand Up @@ -566,7 +574,10 @@ def doit_rp_to_dashboard_update(args):

# Get relevant dashboard result from ElasticSearch
dashboard, es_type, es_id = _get_es_dashboard_result_for_run_id(
session, args, run_id, result["name"],
session,
args,
run_id,
result["name"],
)
if dashboard is None:
logging.warning(
Expand All @@ -580,7 +591,10 @@ def doit_rp_to_dashboard_update(args):
pass # data in the dashboard are correct, no action needed
else:
_update_es_dashboard_result(
session, args, es_id, result_string,
session,
args,
es_id,
result_string,
)
stats["results_changed"] += 1

Expand Down
2 changes: 1 addition & 1 deletion core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"Intended Audience :: Developers",
"Topic :: Software Development :: Quality Assurance",
],
python_requires='>=3.6',
python_requires=">=3.6",
install_requires=[
"Jinja2>=3.0",
"boto3",
Expand Down
4 changes: 3 additions & 1 deletion opl/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ def data_stats(data):
data = [i for i in data if isinstance(i, datetime.datetime) or math.isfinite(i)]
count_strange = data_len_before - len(data)
if count_strange > 0:
logging.warning(f"There were {count_strange} NaN/Inf values in the data. Filtered them out.")
logging.warning(
f"There were {count_strange} NaN/Inf values in the data. Filtered them out."
)

non_zero_data = [i for i in data if i != 0]

Expand Down
22 changes: 18 additions & 4 deletions opl/status_data_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,11 @@ def _get_es_result_for_rp_result(session, args, run_id, result):
def _get_es_dashboard_result_for_run_id(session, args, run_id, test=None):
if test is not None:
response = _es_get_test(
session, args, ["result_id.keyword", "test.keyword"], [run_id, test], sort_by="date"
session,
args,
["result_id.keyword", "test.keyword"],
[run_id, test],
sort_by="date",
)
else:
response = _es_get_test(
Expand Down Expand Up @@ -466,7 +470,9 @@ def doit_rp_to_dashboard_new(args):
session, args, run_id
)
except requests.exceptions.HTTPError as e:
matching = "No mapping found for [date] in order to sort on" in e.response.text
matching = (
"No mapping found for [date] in order to sort on" in e.response.text
)
if e.response.status_code == 400 and matching:
logging.debug(
"Request failed, but I guess it was because index is still empty"
Expand Down Expand Up @@ -503,6 +509,7 @@ def doit_rp_to_dashboard_new(args):
)
print(f"Created result {run_id} in the dashboard with value {result}")


def _update_es_dashboard_result(session, args, es_id, result_string):
url = f"{args.es_server}/{args.es_index}/_doc/{es_id}/_update"
headers = {
Expand All @@ -526,6 +533,7 @@ def _update_es_dashboard_result(session, args, es_id, result_string):
f"Got back this: {json.dumps(response.json(), sort_keys=True, indent=4)}"
)


def doit_rp_to_dashboard_update(args):
assert args.es_server is not None
assert args.rp_host is not None
Expand Down Expand Up @@ -566,7 +574,10 @@ def doit_rp_to_dashboard_update(args):

# Get relevant dashboard result from ElasticSearch
dashboard, es_type, es_id = _get_es_dashboard_result_for_run_id(
session, args, run_id, result["name"],
session,
args,
run_id,
result["name"],
)
if dashboard is None:
logging.warning(
Expand All @@ -580,7 +591,10 @@ def doit_rp_to_dashboard_update(args):
pass # data in the dashboard are correct, no action needed
else:
_update_es_dashboard_result(
session, args, es_id, result_string,
session,
args,
es_id,
result_string,
)
stats["results_changed"] += 1

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"Intended Audience :: Developers",
"Topic :: Software Development :: Quality Assurance",
],
python_requires='>=3.6',
python_requires=">=3.6",
install_requires=[
"Jinja2>=3.0",
"boto3",
Expand Down
21 changes: 11 additions & 10 deletions tests/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import opl.generators.qpc_tarball # noqa: E402
import opl.generators.inventory_ingress # noqa: E402
import opl.generators.inventory_egress # noqa: E402
import opl.generators.packages # noqa: E402
import opl.status_data # noqa: E402
import opl.cluster_read # noqa: E402
import opl.junit_cli # noqa: E402
import opl.args # noqa: E402
import opl # noqa: E402 F401
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

import opl.generators.qpc_tarball # noqa: E402
import opl.generators.inventory_ingress # noqa: E402
import opl.generators.inventory_egress # noqa: E402
import opl.generators.packages # noqa: E402
import opl.status_data # noqa: E402
import opl.cluster_read # noqa: E402
import opl.junit_cli # noqa: E402
import opl.args # noqa: E402
import opl # noqa: E402 F401
3 changes: 1 addition & 2 deletions tests/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@


class TestArgs(unittest.TestCase):

def test_add_storage_db_opts(self):
parser = argparse.ArgumentParser()
opl.args.add_storage_db_opts(parser)
self.assertIn('--storage-db-host', parser.format_help())
self.assertIn("--storage-db-host", parser.format_help())
66 changes: 34 additions & 32 deletions tests/test_cluster_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_date(self):
before = datetime.datetime.utcnow().year
k, v = next(ri)
after = datetime.datetime.utcnow().year
self.assertEqual(k, 'mydate')
self.assertEqual(k, "mydate")
self.assertGreaterEqual(int(v), before)
self.assertGreaterEqual(after, int(v))

Expand All @@ -37,9 +37,9 @@ def test_json(self):
"""
ri = opl.cluster_read.RequestedInfo(string)
k, v = next(ri)
self.assertEqual(k, 'myjson')
self.assertEqual(v['aaa'], 123)
self.assertEqual(v['bbb'], 456)
self.assertEqual(k, "myjson")
self.assertEqual(v["aaa"], 123)
self.assertEqual(v["bbb"], 456)

def test_yaml(self):
string = """
Expand All @@ -49,26 +49,28 @@ def test_yaml(self):
"""
ri = opl.cluster_read.RequestedInfo(string)
k, v = next(ri)
self.assertEqual(k, 'myyaml')
self.assertEqual(v['aaa'], 123)
self.assertEqual(v['bbb'], 456)
self.assertEqual(k, "myyaml")
self.assertEqual(v["aaa"], 123)
self.assertEqual(v["bbb"], 456)

def test_measurements(self):
class TestMeasurementPlugin(opl.cluster_read.BasePlugin):
def measure(self, ri, name, test_measurement_query):
if test_measurement_query == 'simple':
if test_measurement_query == "simple":
return name, opl.data.data_stats([1, 2, 3])

string = """
- name: mymeasurement
test_measurement_query: simple
"""
ri = opl.cluster_read.RequestedInfo(string)
ri.register_measurement_plugin('test_measurement_query', TestMeasurementPlugin({}))
ri.register_measurement_plugin(
"test_measurement_query", TestMeasurementPlugin({})
)
k, v = next(ri)
self.assertEqual(k, 'mymeasurement')
self.assertEqual(v['samples'], 3)
self.assertEqual(v['mean'], 2)
self.assertEqual(k, "mymeasurement")
self.assertEqual(v["samples"], 3)
self.assertEqual(v["mean"], 2)

def test_config_type(self):
string = """
Expand All @@ -77,16 +79,16 @@ def test_config_type(self):
"""
ri = opl.cluster_read.RequestedInfo(string)
k, v = next(ri)
self.assertEqual(k, 'mygreet')
self.assertEqual(v, 'hello')
self.assertEqual(k, "mygreet")
self.assertEqual(v, "hello")
tmp_file = tempfile.mkstemp()[1]
with open(tmp_file, 'w') as fpw:
with open(tmp_file, "w") as fpw:
fpw.write(string)
with open(tmp_file, 'r') as fpr:
with open(tmp_file, "r") as fpr:
ri = opl.cluster_read.RequestedInfo(fpr)
k, v = next(ri)
self.assertEqual(k, 'mygreet')
self.assertEqual(v, 'hello')
self.assertEqual(k, "mygreet")
self.assertEqual(v, "hello")
os.remove(tmp_file)

def test_jinja2_config(self):
Expand All @@ -96,14 +98,14 @@ def test_jinja2_config(self):
command: echo '{{ SOMETHING }}-{{ item }}'
{% endfor %}
"""
os.environ['SOMETHING'] = 'foobarbaz'
os.environ["SOMETHING"] = "foobarbaz"
ri = opl.cluster_read.RequestedInfo(string)
k, v = next(ri)
self.assertEqual(k, 'myenv-1')
self.assertEqual(v, 'foobarbaz-1')
self.assertEqual(k, "myenv-1")
self.assertEqual(v, "foobarbaz-1")
k, v = next(ri)
self.assertEqual(k, 'myenv-2')
self.assertEqual(v, 'foobarbaz-2')
self.assertEqual(k, "myenv-2")
self.assertEqual(v, "foobarbaz-2")

def test_get_config(self):
string = """
Expand All @@ -121,8 +123,8 @@ def test_constant(self):
"""
ri = opl.cluster_read.RequestedInfo(string)
k, v = next(ri)
self.assertEqual(k, 'myconstant')
self.assertEqual(v, 'Hello world')
self.assertEqual(k, "myconstant")
self.assertEqual(v, "Hello world")

def test_copy_from(self):
string = """
Expand All @@ -133,11 +135,11 @@ def test_copy_from(self):
"""
ri = opl.cluster_read.RequestedInfo(string)
k, v = next(ri)
self.assertEqual(k, 'somevalue')
self.assertEqual(v, 'Hello world')
self.assertEqual(k, "somevalue")
self.assertEqual(v, "Hello world")
k, v = next(ri)
self.assertEqual(k, 'mycopyfrom')
self.assertEqual(v, 'Hello world')
self.assertEqual(k, "mycopyfrom")
self.assertEqual(v, "Hello world")

def test_copy_from_negative(self):
string = """
Expand All @@ -148,10 +150,10 @@ def test_copy_from_negative(self):
"""
ri = opl.cluster_read.RequestedInfo(string)
k, v = next(ri)
self.assertEqual(k, 'somevalue')
self.assertEqual(v, 'Hello world')
self.assertEqual(k, "somevalue")
self.assertEqual(v, "Hello world")
k, v = next(ri)
self.assertEqual(k, 'mycopyfrom')
self.assertEqual(k, "mycopyfrom")
self.assertEqual(v, None)

def test_wrong_config(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_generatore_insights_ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def test_count(self):

def test_templates(self):
pg = opl.generators.inventory_ingress.PayloadRHSMGenerator(
count=1,
template='inventory_ingress_RHSM_template.json.j2')
count=1, template="inventory_ingress_RHSM_template.json.j2"
)
mid, msg = next(pg)
pg = opl.generators.inventory_ingress.PayloadRHSMGenerator(
count=1,
template='inventory_ingress_yupana_template.json.j2')
count=1, template="inventory_ingress_yupana_template.json.j2"
)
mid, msg = next(pg)
7 changes: 3 additions & 4 deletions tests/test_generators_insights_egress.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ class TestPayloadGenerator(unittest.TestCase):

def test_counting(self):
pg = opl.generators.inventory_egress.EgressHostsGenerator(
count=3,
n_packages=10,
msg_type='created')
count=3, n_packages=10, msg_type="created"
)
self.assertEqual(pg.count, 3)
self.assertEqual(pg.n_packages, 10)
self.assertEqual(pg.msg_type, 'created')
self.assertEqual(pg.msg_type, "created")

def test_count(self):
pg = opl.generators.inventory_egress.EgressHostsGenerator()
Expand Down
8 changes: 5 additions & 3 deletions tests/test_generators_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def test_looks_like_package_name(self):
pg = opl.generators.packages.PackagesGenerator()
for p in pg.generate(10):
self.assertIsInstance(p, str)
self.assertTrue(p.endswith('x86_64') or p.endswith('i686') or p.endswith('noarch'))
self.assertTrue(' ' not in p)
self.assertGreater(len(p), 9) # minimum is 'a-1.noarch' I think
self.assertTrue(
p.endswith("x86_64") or p.endswith("i686") or p.endswith("noarch")
)
self.assertTrue(" " not in p)
self.assertGreater(len(p), 9) # minimum is 'a-1.noarch' I think
1 change: 0 additions & 1 deletion tests/test_generators_qpc_tarball.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def test_add_hosts(self):
tarball_slice.add_host({"fqdn": f"host{i}.example.com"})
self.assertEqual(tarball_slice.get_host_count(), 4)


def test_slice_after_dump(self):
pg = opl.generators.qpc_tarball.QPCTarballGenerator(
count=2, tarball_conf=self.tarball_conf
Expand Down
Loading

0 comments on commit df1663b

Please sign in to comment.