From e200cd32892ead596c74226519382aa950f20a6f Mon Sep 17 00:00:00 2001 From: Leigh Morresi <275001+dgtlmoon@users.noreply.github.com> Date: Sun, 21 Feb 2021 14:26:19 +0100 Subject: [PATCH] Fixing a few more easy lint wins --- backend/__init__.py | 9 +++------ backend/dev-docker/sleep.py | 4 +--- backend/fetch_site_status.py | 1 - backend/store.py | 3 +-- backend/tests/conftest.py | 18 +++--------------- backend/tests/test_backend.py | 9 ++------- 6 files changed, 10 insertions(+), 34 deletions(-) diff --git a/backend/__init__.py b/backend/__init__.py index 690dd51a..028d49b7 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -374,7 +374,7 @@ def changedetection_app(config=None, datastore_o=None): # @todo check thread is running and skip if uuid: - if not uuid in running_uuids: + if uuid not in running_uuids: update_q.put(uuid) i = 1 @@ -383,13 +383,13 @@ def changedetection_app(config=None, datastore_o=None): for watch_uuid, watch in datastore.data['watching'].items(): if (tag != None and tag in watch['tag']): i += 1 - if not watch_uuid in running_uuids: + if watch_uuid not in running_uuids: update_q.put(watch_uuid) else: # No tag, no uuid, add everything. for watch_uuid, watch in datastore.data['watching'].items(): i += 1 - if not watch_uuid in running_uuids: + if watch_uuid not in running_uuids: update_q.put(watch_uuid) messages.append({'class': 'ok', 'message': "{} watches are rechecking.".format(i)}) @@ -443,9 +443,6 @@ class Worker(threading.Thread): # A change was detected datastore.save_history_text(uuid=uuid, contents=contents, result_obj=result) - else: - # No change - x = 1 self.current_uuid = None # Done self.q.task_done() diff --git a/backend/dev-docker/sleep.py b/backend/dev-docker/sleep.py index e2108f0f..27c632b5 100644 --- a/backend/dev-docker/sleep.py +++ b/backend/dev-docker/sleep.py @@ -1,9 +1,7 @@ import time -import sys print ("Sleep loop, you should run your script from the console") while True: # Wait for 5 seconds - - time.sleep(2) \ No newline at end of file + time.sleep(2) diff --git a/backend/fetch_site_status.py b/backend/fetch_site_status.py index f71ecd7a..f03cdb00 100644 --- a/backend/fetch_site_status.py +++ b/backend/fetch_site_status.py @@ -48,7 +48,6 @@ class perform_site_check(): stripped_text_from_html = get_text(r.text) - # Usually from networkIO/requests level except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout) as e: update_obj["last_error"] = str(e) diff --git a/backend/store.py b/backend/store.py index 4acaa175..1600dd1f 100644 --- a/backend/store.py +++ b/backend/store.py @@ -1,9 +1,8 @@ import json import uuid as uuid_builder -import validators import os.path from os import path -from threading import Lock, Thread +from threading import Lock from copy import deepcopy diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index 7dfa2ebe..2c2fa334 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -3,6 +3,7 @@ import pytest from backend import changedetection_app from backend import store +import os # https://github.com/pallets/flask/blob/1.1.2/examples/tutorial/tests/test_auth.py @@ -19,37 +20,24 @@ def app(request): datastore_path = "./test-datastore" - import os try: os.mkdir(datastore_path) except FileExistsError: pass - try: os.unlink("{}/url-watches.json".format(datastore_path)) except FileNotFoundError: pass - app_config = {'datastore_path': datastore_path} datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path'], include_default_watches=False) app = changedetection_app(app_config, datastore) - # Establish an application context before running the tests. - #ctx = _app.app_context() - #ctx.push() - def teardown(): datastore.stop_thread = True - app.config['STOP_THREADS']= True + app.config['STOP_THREADS'] = True request.addfinalizer(teardown) - return app - -#@pytest.fixture(scope='session') -#def client(app): -# with app.test_client() as client: -# yield client - + return app diff --git a/backend/tests/test_backend.py b/backend/tests/test_backend.py index fcdf8519..f1fdff19 100644 --- a/backend/tests/test_backend.py +++ b/backend/tests/test_backend.py @@ -1,12 +1,11 @@ #!/usr/bin/python3 import time -import pytest from flask import url_for from urllib.request import urlopen -def set_original_response(): +def set_original_response(): test_return_data = """ Some initial text
@@ -42,7 +41,6 @@ def test_check_basic_change_detection_functionality(client, live_server): sleep_time_for_fetch_thread = 3 @live_server.app.route('/test-endpoint') - def test_endpoint(): # Tried using a global var here but didn't seem to work, so reading from a file instead. with open("test-datastore/output.txt", "r") as f: @@ -76,8 +74,7 @@ def test_check_basic_change_detection_functionality(client, live_server): assert b'unviewed' not in res.data -##################### - + ##################### # Make a change set_modified_response() @@ -85,7 +82,6 @@ def test_check_basic_change_detection_functionality(client, live_server): res = urlopen(url_for('test_endpoint', _external=True)) assert b'which has this one new line' in res.read() - # Force recheck res = client.get(url_for("api_watch_checknow"), follow_redirects=True) assert b'1 watches are rechecking.' in res.data @@ -95,4 +91,3 @@ def test_check_basic_change_detection_functionality(client, live_server): # Now something should be ready, indicated by having a 'unviewed' class res = client.get(url_for("index")) assert b'unviewed' in res.data -