From c1a35a78595b4d75ac845af322f69a42c6f72bd3 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Fri, 11 Aug 2023 14:17:20 +0200 Subject: add doc strings and use more meaningful variable names --- test.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/test.py b/test.py index 8d217ca..0ace942 100755 --- a/test.py +++ b/test.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +"""System tests for the geldschieberbot""" from datetime import datetime, date, timedelta import json @@ -78,6 +79,7 @@ def _run_bot(sender, cmd): def run_bot(test, sender, cmd): + """Run the bot and check its status and error messages""" res = _run_bot(sender, cmd) test.assertEqual(res.returncode, 0) test.assertEqual(res.stderr, "") @@ -85,10 +87,12 @@ def run_bot(test, sender, cmd): def save_state(dest): + """Copy the used state file to a different location""" copyfile(os.environ["GSB_STATE_FILE"], dest) def reset_state(state=None): + """Reset or delete the used state file""" if state: copyfile(state, os.environ["GSB_STATE_FILE"]) else: @@ -98,24 +102,27 @@ def reset_state(state=None): def reset_state_string(string): - with open(os.environ["GSB_STATE_FILE"], "w", encoding='utf-8') as f: - json.dump(json.loads(string), f) + """Reset the used state to a string""" + with open(os.environ["GSB_STATE_FILE"], "w", + encoding='utf-8') as state_file: + json.dump(json.loads(string), state_file) def compare_state(expected_state_path, state=None, state_path=os.environ["GSB_STATE_FILE"]) -> bool: - s = '' + """Compare to states""" + state_str = '' if state is None: - with open(state_path, "r", encoding='utf-8') as sf: - s = sf.read() + with open(state_path, "r", encoding='utf-8') as state_file: + state_str = state_file.read() else: - s = json.dumps(state, cls=GeldschieberbotJSONEncoder) + state_str = json.dumps(state, cls=GeldschieberbotJSONEncoder) - with open(expected_state_path, "r", encoding='utf-8') as csf: - cs = csf.read() + with open(expected_state_path, "r", encoding='utf-8') as exp_state_file: + expected_state_str = exp_state_file.read() - return cs == s + return expected_state_str == state_str # pragma pylint: disable=missing-function-docstring,missing-class-docstring,invalid-name -- cgit v1.2.3