commit 68cb95ba1a74a50791714c0ceb1993a831b19ac2 Author: juga0 juga@riseup.net Date: Tue Mar 16 19:10:34 2021 +0000
fix: Reorder imports with isort --- sbws/core/cleanup.py | 17 +++++---- sbws/core/generate.py | 22 ++++++------ sbws/core/scanner.py | 50 +++++++++++++------------- sbws/core/stats.py | 24 +++++++------ sbws/globals.py | 7 ++-- sbws/lib/bwfile_health.py | 13 +++---- sbws/lib/circuitbuilder.py | 12 +++++-- sbws/lib/destination.py | 13 +++---- sbws/lib/heartbeat.py | 1 - sbws/lib/relaylist.py | 10 +++--- sbws/lib/relayprioritizer.py | 9 +++-- sbws/lib/resultdump.py | 21 ++++++----- sbws/lib/v3bwfile.py | 21 +++++------ sbws/sbws.py | 18 +++++----- sbws/util/config.py | 15 ++++---- sbws/util/filelock.py | 3 +- sbws/util/json.py | 2 +- sbws/util/parser.py | 8 ++--- sbws/util/state.py | 5 +-- sbws/util/stem.py | 38 ++++++++++---------- sbws/util/timestamps.py | 2 +- tests/conftest.py | 6 ++-- tests/integration/conftest.py | 3 +- tests/integration/core/test_scanner.py | 3 +- tests/integration/lib/test_destination.py | 2 +- tests/integration/lib/test_relayprioritizer.py | 5 ++- tests/integration/util/test_requests.py | 3 +- tests/unit/conftest.py | 14 +++++--- tests/unit/core/test_generate.py | 2 +- tests/unit/core/test_stats.py | 4 +-- tests/unit/lib/test_heartbeat.py | 1 + tests/unit/lib/test_resultdump.py | 2 +- tests/unit/lib/test_results.py | 20 ++++++----- tests/unit/lib/test_scaling.py | 2 +- tests/unit/lib/test_v3bwfile.py | 23 ++++++------ tests/unit/util/test_config.py | 3 +- tests/unit/util/test_state.py | 3 +- tests/unit/util/test_timestamp.py | 6 ++-- tests/unit/util/test_timestamps.py | 5 +-- tests/unit/util/test_userquery.py | 1 + 40 files changed, 215 insertions(+), 204 deletions(-)
diff --git a/sbws/core/cleanup.py b/sbws/core/cleanup.py index 8b7e6fd..dd43f9c 100644 --- a/sbws/core/cleanup.py +++ b/sbws/core/cleanup.py @@ -1,17 +1,16 @@ """Util functions to cleanup disk space.""" +import gzip +import logging +import os +import shutil +import time import types +from argparse import ArgumentDefaultsHelpFormatter +from datetime import datetime, timedelta
-from sbws.util.filelock import DirectoryLock from sbws.globals import fail_hard +from sbws.util.filelock import DirectoryLock from sbws.util.timestamp import unixts_to_dt_obj -from argparse import ArgumentDefaultsHelpFormatter -from datetime import datetime -from datetime import timedelta -import os -import gzip -import shutil -import logging -import time
log = logging.getLogger(__name__)
diff --git a/sbws/core/generate.py b/sbws/core/generate.py index 55bf719..ecc0b53 100644 --- a/sbws/core/generate.py +++ b/sbws/core/generate.py @@ -1,23 +1,23 @@ +import logging +import os +from argparse import ArgumentDefaultsHelpFormatter from math import ceil
from sbws.globals import ( - fail_hard, + DAY_SECS, + GENERATE_PERIOD, + NUM_MIN_RESULTS, + PROP276_ROUND_DIG, SBWS_SCALE_CONSTANT, - TORFLOW_SCALING, SBWS_SCALING, TORFLOW_BW_MARGIN, - PROP276_ROUND_DIG, - DAY_SECS, - NUM_MIN_RESULTS, - GENERATE_PERIOD, + TORFLOW_SCALING, + fail_hard, ) -from sbws.lib.v3bwfile import V3BWFile +from sbws.lib import destination from sbws.lib.resultdump import load_recent_results_in_datadir -from argparse import ArgumentDefaultsHelpFormatter -import os -import logging +from sbws.lib.v3bwfile import V3BWFile from sbws.util.timestamp import now_fname -from sbws.lib import destination
log = logging.getLogger(__name__)
diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py index ab5a99a..38ddef2 100644 --- a/sbws/core/scanner.py +++ b/sbws/core/scanner.py @@ -1,44 +1,42 @@ """ Measure the relays. """ +import logging +import os import queue - +import random import signal import sys import threading +import time import traceback import uuid - +from argparse import ArgumentDefaultsHelpFormatter from multiprocessing.context import TimeoutError +from multiprocessing.dummy import Pool + +import sbws.util.requests as requests_utils +import sbws.util.stem as stem_utils +from sbws.globals import HTTP_GET_HEADERS, TIMEOUT_MEASUREMENTS, fail_hard
+from .. import settings from ..lib.circuitbuilder import GapsCircuitBuilder as CB -from ..lib.resultdump import ResultDump -from ..lib.resultdump import ( - ResultSuccess, - ResultErrorCircuit, - ResultErrorStream, - ResultErrorSecondRelay, - ResultError, - ResultErrorDestination, -) -from ..lib.relaylist import RelayList -from ..lib.relayprioritizer import RelayPrioritizer from ..lib.destination import ( DestinationList, connect_to_destination_over_circuit, ) -from ..util.timestamp import now_isodt_str -from ..util.state import State -from sbws.globals import fail_hard, HTTP_GET_HEADERS, TIMEOUT_MEASUREMENTS -import sbws.util.stem as stem_utils -import sbws.util.requests as requests_utils -from argparse import ArgumentDefaultsHelpFormatter -from multiprocessing.dummy import Pool -import time -import os -import logging -import random - -from .. import settings from ..lib.heartbeat import Heartbeat +from ..lib.relaylist import RelayList +from ..lib.relayprioritizer import RelayPrioritizer +from ..lib.resultdump import ( + ResultDump, + ResultError, + ResultErrorCircuit, + ResultErrorDestination, + ResultErrorSecondRelay, + ResultErrorStream, + ResultSuccess, +) +from ..util.state import State +from ..util.timestamp import now_isodt_str
rng = random.SystemRandom() log = logging.getLogger(__name__) diff --git a/sbws/core/stats.py b/sbws/core/stats.py index 9f80885..bd8c88b 100644 --- a/sbws/core/stats.py +++ b/sbws/core/stats.py @@ -1,16 +1,18 @@ -from sbws.globals import fail_hard -from sbws.lib.resultdump import Result -from sbws.lib.resultdump import ResultError -from sbws.lib.resultdump import ResultErrorCircuit -from sbws.lib.resultdump import ResultErrorStream -from sbws.lib.resultdump import ResultSuccess -from sbws.lib.resultdump import load_recent_results_in_datadir -from argparse import ArgumentDefaultsHelpFormatter +import logging import os -from datetime import datetime -from datetime import timedelta +from argparse import ArgumentDefaultsHelpFormatter +from datetime import datetime, timedelta from statistics import mean -import logging + +from sbws.globals import fail_hard +from sbws.lib.resultdump import ( + Result, + ResultError, + ResultErrorCircuit, + ResultErrorStream, + ResultSuccess, + load_recent_results_in_datadir, +)
log = logging.getLogger(__name__)
diff --git a/sbws/globals.py b/sbws/globals.py index cb6a4c3..4658868 100644 --- a/sbws/globals.py +++ b/sbws/globals.py @@ -1,16 +1,13 @@ -import os import logging +import os import platform +from collections import OrderedDict
from requests import __version__ as requests_version from stem import __version__ as stem_version
from sbws import __version__
- -from collections import OrderedDict - - log = logging.getLogger(__name__)
RESULT_VERSION = 4 diff --git a/sbws/lib/bwfile_health.py b/sbws/lib/bwfile_health.py index 1c060ab..9378fd6 100644 --- a/sbws/lib/bwfile_health.py +++ b/sbws/lib/bwfile_health.py @@ -5,14 +5,11 @@ import logging
from stem import descriptor
-from sbws.globals import ( - PERIOD_DAYS, - FRACTION_RELAYS, - MAX_RECENT_PRIORITY_RELAY_COUNT, # 48000 - MAX_RECENT_PRIORITY_LIST_COUNT, # 120 - MAX_RECENT_CONSENSUS_COUNT, # 120 -) -from sbws.lib.v3bwfile import HEADER_INT_KEYS, BWLINE_KEYS_V1_4 +from sbws.globals import MAX_RECENT_CONSENSUS_COUNT # 120 +from sbws.globals import MAX_RECENT_PRIORITY_LIST_COUNT # 120 +from sbws.globals import MAX_RECENT_PRIORITY_RELAY_COUNT # 48000 +from sbws.globals import FRACTION_RELAYS, PERIOD_DAYS +from sbws.lib.v3bwfile import BWLINE_KEYS_V1_4, HEADER_INT_KEYS
logging.basicConfig( level=logging.INFO, diff --git a/sbws/lib/circuitbuilder.py b/sbws/lib/circuitbuilder.py index d96e5ec..8b9c520 100644 --- a/sbws/lib/circuitbuilder.py +++ b/sbws/lib/circuitbuilder.py @@ -1,7 +1,15 @@ -from stem import CircuitExtensionFailed, InvalidRequest, ProtocolError, Timeout -from stem import InvalidArguments, ControllerError, SocketClosed import logging
+from stem import ( + CircuitExtensionFailed, + ControllerError, + InvalidArguments, + InvalidRequest, + ProtocolError, + SocketClosed, + Timeout, +) + log = logging.getLogger(__name__)
diff --git a/sbws/lib/destination.py b/sbws/lib/destination.py index a2bc855..28951a9 100644 --- a/sbws/lib/destination.py +++ b/sbws/lib/destination.py @@ -2,21 +2,22 @@ import collections import datetime import logging import random -import requests from urllib.parse import urlparse + +import requests from stem.control import EventType
-from sbws.globals import DESTINATION_VERIFY_CERTIFICATE import sbws.util.stem as stem_utils +from sbws import settings +from sbws.globals import DESTINATION_VERIFY_CERTIFICATE + from ..globals import ( - MAX_NUM_DESTINATION_FAILURES, DELTA_SECONDS_RETRY_DESTINATION, + FACTOR_INCREMENT_DESTINATION_RETRY, + MAX_NUM_DESTINATION_FAILURES, MAX_SECONDS_RETRY_DESTINATION, NUM_DESTINATION_ATTEMPTS_STORED, - FACTOR_INCREMENT_DESTINATION_RETRY, ) -from sbws import settings -
log = logging.getLogger(__name__)
diff --git a/sbws/lib/heartbeat.py b/sbws/lib/heartbeat.py index 89d6198..84ccf5b 100644 --- a/sbws/lib/heartbeat.py +++ b/sbws/lib/heartbeat.py @@ -6,7 +6,6 @@ import time
from ..util.state import State
- log = logging.getLogger(__name__)
diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py index 06de489..0128786 100644 --- a/sbws/lib/relaylist.py +++ b/sbws/lib/relaylist.py @@ -1,17 +1,17 @@ import copy +import logging +import random from datetime import datetime, timedelta +from threading import Lock
+from stem import ControllerError, DescriptorUnavailable, Flag from stem.descriptor.router_status_entry import RouterStatusEntryV3 from stem.descriptor.server_descriptor import ServerDescriptor -from stem import Flag, DescriptorUnavailable, ControllerError -import random -import logging -from threading import Lock
from ..globals import ( MAX_RECENT_CONSENSUS_COUNT, - MAX_RECENT_PRIORITY_RELAY_COUNT, MAX_RECENT_PRIORITY_LIST_COUNT, + MAX_RECENT_PRIORITY_RELAY_COUNT, MEASUREMENTS_PERIOD, ) from ..util import timestamps diff --git a/sbws/lib/relayprioritizer.py b/sbws/lib/relayprioritizer.py index e734e03..f70c7a6 100644 --- a/sbws/lib/relayprioritizer.py +++ b/sbws/lib/relayprioritizer.py @@ -1,12 +1,11 @@ -from decimal import Decimal -from ..lib.resultdump import ResultDump -from ..lib.resultdump import ResultError -from ..lib.relaylist import RelayList import copy -import time import logging +import time +from decimal import Decimal
from ..globals import MAX_RECENT_PRIORITY_RELAY_COUNT +from ..lib.relaylist import RelayList +from ..lib.resultdump import ResultDump, ResultError from ..util import state, timestamps
log = logging.getLogger(__name__) diff --git a/sbws/lib/resultdump.py b/sbws/lib/resultdump.py index 58543b2..5ef45de 100644 --- a/sbws/lib/resultdump.py +++ b/sbws/lib/resultdump.py @@ -1,19 +1,18 @@ -import os import json -import time import logging -from glob import glob -from threading import Thread -from threading import RLock -from queue import Queue -from queue import Empty -from datetime import datetime -from datetime import timedelta +import os +import time +from datetime import datetime, timedelta from enum import Enum +from glob import glob +from queue import Empty, Queue +from threading import RLock, Thread + from sbws.globals import RESULT_VERSION, fail_hard -from sbws.util.filelock import DirectoryLock -from sbws.util.json import CustomEncoder, CustomDecoder from sbws.lib.relaylist import Relay +from sbws.util.filelock import DirectoryLock +from sbws.util.json import CustomDecoder, CustomEncoder + from .. import settings
log = logging.getLogger(__name__) diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py index bb9b028..45a974b 100644 --- a/sbws/lib/v3bwfile.py +++ b/sbws/lib/v3bwfile.py @@ -9,34 +9,35 @@ import logging import math import os from itertools import combinations -from statistics import median, mean +from statistics import mean, median + from stem.descriptor import parse_file
from sbws import __version__ from sbws.globals import ( - SPEC_VERSION, BW_LINE_SIZE, + MAX_BW_DIFF_PERC, + MIN_REPORT, + PROP276_ROUND_DIG, SBWS_SCALE_CONSTANT, - TORFLOW_SCALING, SBWS_SCALING, + SPEC_VERSION, TORFLOW_BW_MARGIN, TORFLOW_OBS_LAST, TORFLOW_OBS_MEAN, - PROP276_ROUND_DIG, - MIN_REPORT, - MAX_BW_DIFF_PERC, + TORFLOW_SCALING, ) from sbws.lib import scaling from sbws.lib.resultdump import ResultSuccess, _ResultType from sbws.util.filelock import DirectoryLock +from sbws.util.state import State from sbws.util.timestamp import ( + dt_obj_to_isodt_str, + isostr_to_dt_obj, now_isodt_str, - unixts_to_isodt_str, now_unixts, - isostr_to_dt_obj, - dt_obj_to_isodt_str, + unixts_to_isodt_str, ) -from sbws.util.state import State
log = logging.getLogger(__name__)
diff --git a/sbws/sbws.py b/sbws/sbws.py index 7639ba5..fdd2a8a 100644 --- a/sbws/sbws.py +++ b/sbws/sbws.py @@ -1,20 +1,18 @@ +import logging import os +import platform + +from requests.__version__ import __version__ as requests_version +from stem import __version__ as stem_version
import sbws.core.cleanup -import sbws.core.scanner import sbws.core.generate +import sbws.core.scanner import sbws.core.stats -from sbws.util.config import get_config -from sbws.util.config import validate_config -from sbws.util.config import configure_logging -from sbws.util.parser import create_parser from sbws import __version__ as version -from stem import __version__ as stem_version -from requests.__version__ import __version__ as requests_version -import platform -import logging - +from sbws.util.config import configure_logging, get_config, validate_config from sbws.util.fs import sbws_required_disk_space +from sbws.util.parser import create_parser
log = logging.getLogger(__name__)
diff --git a/sbws/util/config.py b/sbws/util/config.py index 8d18b12..e5e69f9 100644 --- a/sbws/util/config.py +++ b/sbws/util/config.py @@ -1,21 +1,24 @@ """Util functions to manage sbws configuration files."""
-from configparser import ConfigParser, ExtendedInterpolation -from configparser import InterpolationMissingOptionError -import os import logging import logging.config -from urllib.parse import urlparse +import os +from configparser import ( + ConfigParser, + ExtendedInterpolation, + InterpolationMissingOptionError, +) from string import Template from tempfile import NamedTemporaryFile +from urllib.parse import urlparse + from sbws.globals import ( DEFAULT_CONFIG_PATH, DEFAULT_LOG_CONFIG_PATH, - USER_CONFIG_PATH, SUPERVISED_RUN_DPATH, SUPERVISED_USER_CONFIG_PATH, + USER_CONFIG_PATH, ) - from sbws.util.iso3166 import ISO_3166_ALPHA_2
_ALPHANUM = "abcdefghijklmnopqrstuvwxyz" diff --git a/sbws/util/filelock.py b/sbws/util/filelock.py index 9a70ece..8206934 100644 --- a/sbws/util/filelock.py +++ b/sbws/util/filelock.py @@ -1,6 +1,7 @@ -import os import fcntl import logging +import os + from sbws.globals import fail_hard
log = logging.getLogger(__name__) diff --git a/sbws/util/json.py b/sbws/util/json.py index f4f8130..b5b54ed 100644 --- a/sbws/util/json.py +++ b/sbws/util/json.py @@ -2,7 +2,7 @@ import datetime import json
-from .timestamps import DateTimeSeq, DateTimeIntSeq +from .timestamps import DateTimeIntSeq, DateTimeSeq
class CustomEncoder(json.JSONEncoder): diff --git a/sbws/util/parser.py b/sbws/util/parser.py index 6ded1f6..df82139 100644 --- a/sbws/util/parser.py +++ b/sbws/util/parser.py @@ -1,12 +1,12 @@ +import os +from argparse import ArgumentParser, RawTextHelpFormatter + import sbws.core.cleanup -import sbws.core.scanner import sbws.core.generate +import sbws.core.scanner import sbws.core.stats from sbws import __version__
-from argparse import ArgumentParser, RawTextHelpFormatter -import os -
def _default_dot_sbws_dname(): home = os.path.expanduser("~") diff --git a/sbws/util/state.py b/sbws/util/state.py index ce01f95..c2b04fc 100644 --- a/sbws/util/state.py +++ b/sbws/util/state.py @@ -1,6 +1,7 @@ -from sbws.util.filelock import FileLock -import os import json +import os + +from sbws.util.filelock import FileLock
from .json import CustomDecoder, CustomEncoder
diff --git a/sbws/util/stem.py b/sbws/util/stem.py index 53260e2..f2bea86 100644 --- a/sbws/util/stem.py +++ b/sbws/util/stem.py @@ -1,35 +1,35 @@ -import socks +import copy +import logging +import os +from threading import RLock
-from stem.control import Controller, Listener +import socks +import stem.process from stem import ( - SocketError, - InvalidRequest, - UnsatisfiableRequest, - OperationFailed, ControllerError, + Flag, InvalidArguments, + InvalidRequest, + OperationFailed, ProtocolError, SocketClosed, + SocketError, + UnsatisfiableRequest, ) from stem.connection import IncorrectSocketType -import stem.process -from threading import RLock -import copy -import logging -import os -from sbws.globals import fail_hard +from stem.control import Controller, Listener + +from sbws import settings from sbws.globals import ( - TORRC_STARTING_POINT, - TORRC_RUNTIME_OPTIONS, + GE, TORRC_OPTIONS_CAN_FAIL, + TORRC_RUNTIME_OPTIONS, + TORRC_STARTING_POINT, + E, G, M, - E, - GE, + fail_hard, ) -from sbws import settings - -from stem import Flag
log = logging.getLogger(__name__) stream_building_lock = RLock() diff --git a/sbws/util/timestamps.py b/sbws/util/timestamps.py index 393b30b..a6c8292 100644 --- a/sbws/util/timestamps.py +++ b/sbws/util/timestamps.py @@ -6,8 +6,8 @@ Optionally update also a state file. # Workarounds to store datetimes for objects because they are not compossed # by other objects nor stored in a database with a creation datetime. import collections -from datetime import datetime, timedelta import logging +from datetime import datetime, timedelta
from sbws.util.timestamp import is_old
diff --git a/tests/conftest.py b/tests/conftest.py index fb3924b..a289ade 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,15 +1,13 @@ """Common pytest configuration for unit and integration tests.""" -import pytest import os.path from unittest import mock
+import pytest from freezegun import freeze_time from stem import descriptor
from sbws import settings -from sbws.lib import relaylist -from sbws.lib import relayprioritizer -from sbws.lib import resultdump +from sbws.lib import relaylist, relayprioritizer, resultdump from sbws.util.parser import create_parser
diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 37b4ea5..c90a788 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -1,8 +1,9 @@ """pytest configuration for integration tests.""" import argparse -import pytest import os
+import pytest + from sbws.lib.circuitbuilder import GapsCircuitBuilder as CB from sbws.lib.destination import DestinationList from sbws.lib.relaylist import RelayList diff --git a/tests/integration/core/test_scanner.py b/tests/integration/core/test_scanner.py index ca18ba0..0a2196a 100644 --- a/tests/integration/core/test_scanner.py +++ b/tests/integration/core/test_scanner.py @@ -1,8 +1,9 @@ +import logging + import pytest
from sbws.core.scanner import measure_relay from sbws.lib.resultdump import ResultSuccess -import logging
def assert_within(value, target, radius): diff --git a/tests/integration/lib/test_destination.py b/tests/integration/lib/test_destination.py index a00e61e..3190e39 100644 --- a/tests/integration/lib/test_destination.py +++ b/tests/integration/lib/test_destination.py @@ -1,8 +1,8 @@ """Integration tests for destination.py""" import sbws.util.requests as requests_utils from sbws.lib.destination import ( - DestinationList, Destination, + DestinationList, connect_to_destination_over_circuit, )
diff --git a/tests/integration/lib/test_relayprioritizer.py b/tests/integration/lib/test_relayprioritizer.py index 05a6b49..407bd89 100644 --- a/tests/integration/lib/test_relayprioritizer.py +++ b/tests/integration/lib/test_relayprioritizer.py @@ -1,9 +1,8 @@ -from sbws.lib.resultdump import ResultDump -from sbws.lib.resultdump import ResultSuccess, ResultErrorCircuit -from sbws.lib.relayprioritizer import RelayPrioritizer from unittest.mock import patch
from sbws import settings +from sbws.lib.relayprioritizer import RelayPrioritizer +from sbws.lib.resultdump import ResultDump, ResultErrorCircuit, ResultSuccess
def static_time(value): diff --git a/tests/integration/util/test_requests.py b/tests/integration/util/test_requests.py index 9c126bc..d0555c1 100644 --- a/tests/integration/util/test_requests.py +++ b/tests/integration/util/test_requests.py @@ -1,7 +1,8 @@ """Integration tests for requests.""" -import requests import uuid
+import requests + from sbws import settings from sbws.util import requests as requests_utils
diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 893b045..da6a90d 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -1,15 +1,19 @@ """pytest configuration for unit tests.""" import argparse -import pytest -from datetime import datetime import os +from datetime import datetime + +import pytest
from sbws.globals import RESULT_VERSION -from sbws.lib.resultdump import ResultErrorStream, ResultSuccess, Result -from sbws.lib.resultdump import write_result_to_datadir +from sbws.lib.resultdump import ( + Result, + ResultErrorStream, + ResultSuccess, + write_result_to_datadir, +) from sbws.util.config import _get_default_config
- TIME1 = 1529232277.9028733 TIME2 = datetime.utcnow().timestamp() FP1 = "A" * 40 diff --git a/tests/unit/core/test_generate.py b/tests/unit/core/test_generate.py index 9c7a0d2..539bf79 100644 --- a/tests/unit/core/test_generate.py +++ b/tests/unit/core/test_generate.py @@ -1,8 +1,8 @@ """Unit tests for sbws.core.generate module.""" import argparse
-from sbws.globals import TORFLOW_ROUND_DIG, PROP276_ROUND_DIG from sbws.core.generate import gen_parser +from sbws.globals import PROP276_ROUND_DIG, TORFLOW_ROUND_DIG
def test_gen_parser_arg_round_digs(): diff --git a/tests/unit/core/test_stats.py b/tests/unit/core/test_stats.py index 04d6f6c..1dc7f32 100644 --- a/tests/unit/core/test_stats.py +++ b/tests/unit/core/test_stats.py @@ -1,9 +1,9 @@ +import logging import os.path +from unittest.mock import patch
import sbws.core.stats from tests.unit.globals import monotonic_time -from unittest.mock import patch -import logging
def test_stats_initted(sbwshome_empty, args, conf, caplog): diff --git a/tests/unit/lib/test_heartbeat.py b/tests/unit/lib/test_heartbeat.py index 1e8e876..a6aaa65 100644 --- a/tests/unit/lib/test_heartbeat.py +++ b/tests/unit/lib/test_heartbeat.py @@ -1,5 +1,6 @@ """Unit tests for heartbeat""" import logging + import pytest
from sbws.lib import heartbeat diff --git a/tests/unit/lib/test_resultdump.py b/tests/unit/lib/test_resultdump.py index f85e0d1..2a5f7f6 100644 --- a/tests/unit/lib/test_resultdump.py +++ b/tests/unit/lib/test_resultdump.py @@ -9,8 +9,8 @@ from sbws.lib.resultdump import ( ResultError, ResultErrorStream, ResultSuccess, - trim_results_ip_changed, load_result_file, + trim_results_ip_changed, )
diff --git a/tests/unit/lib/test_results.py b/tests/unit/lib/test_results.py index d1a9146..7db88ab 100644 --- a/tests/unit/lib/test_results.py +++ b/tests/unit/lib/test_results.py @@ -1,15 +1,17 @@ from unittest.mock import patch -from sbws.globals import RESULT_VERSION -from sbws.lib.resultdump import Result -from sbws.lib.resultdump import ResultSuccess -from sbws.lib.resultdump import ResultError -from sbws.lib.resultdump import ResultErrorAuth -from sbws.lib.resultdump import ResultErrorCircuit -from sbws.lib.resultdump import ResultErrorStream -from sbws.lib.resultdump import _ResultType -from tests.unit.globals import monotonic_time
+from sbws.globals import RESULT_VERSION from sbws.lib.relaylist import Relay +from sbws.lib.resultdump import ( + Result, + ResultError, + ResultErrorAuth, + ResultErrorCircuit, + ResultErrorStream, + ResultSuccess, + _ResultType, +) +from tests.unit.globals import monotonic_time
def test_Result(result): diff --git a/tests/unit/lib/test_scaling.py b/tests/unit/lib/test_scaling.py index baf195f..c510d23 100644 --- a/tests/unit/lib/test_scaling.py +++ b/tests/unit/lib/test_scaling.py @@ -3,7 +3,7 @@ import os from statistics import mean
from sbws.lib import scaling -from sbws.lib.resultdump import load_result_file, ResultSuccess +from sbws.lib.resultdump import ResultSuccess, load_result_file
def test_bw_filt(): diff --git a/tests/unit/lib/test_v3bwfile.py b/tests/unit/lib/test_v3bwfile.py index 6fc3163..cb26474 100644 --- a/tests/unit/lib/test_v3bwfile.py +++ b/tests/unit/lib/test_v3bwfile.py @@ -4,29 +4,30 @@ import json import logging import math import os.path -import pytest from unittest import mock
+import pytest + from sbws import __version__ as version from sbws.globals import ( - SPEC_VERSION, - SBWS_SCALING, - TORFLOW_SCALING, MIN_REPORT, - TORFLOW_ROUND_DIG, PROP276_ROUND_DIG, + SBWS_SCALING, + SPEC_VERSION, + TORFLOW_ROUND_DIG, + TORFLOW_SCALING, ) -from sbws.lib.resultdump import Result, load_result_file, ResultSuccess +from sbws.lib.resultdump import Result, ResultSuccess, load_result_file from sbws.lib.v3bwfile import ( + HEADER_RECENT_MEASUREMENTS_EXCLUDED_KEYS, + KEYVALUE_SEP_V1, + LINE_SEP, + TERMINATOR, + V3BWFile, V3BWHeader, V3BWLine, - TERMINATOR, - LINE_SEP, - KEYVALUE_SEP_V1, num_results_of_type, - V3BWFile, round_sig_dig, - HEADER_RECENT_MEASUREMENTS_EXCLUDED_KEYS, ) from sbws.util.state import CustomDecoder from sbws.util.timestamp import now_fname, now_isodt_str, now_unixts diff --git a/tests/unit/util/test_config.py b/tests/unit/util/test_config.py index 48b784f..603c5bd 100644 --- a/tests/unit/util/test_config.py +++ b/tests/unit/util/test_config.py @@ -1,6 +1,7 @@ -import sbws.util.config as con from configparser import ConfigParser
+import sbws.util.config as con +
class PseudoSection: def __init__(self, key, value, mini=None, maxi=None): diff --git a/tests/unit/util/test_state.py b/tests/unit/util/test_state.py index f8a0072..3937ce5 100644 --- a/tests/unit/util/test_state.py +++ b/tests/unit/util/test_state.py @@ -1,6 +1,7 @@ -from sbws.util.state import State import os
+from sbws.util.state import State + # from tempfile import NamedTemporaryFile as NTF
diff --git a/tests/unit/util/test_timestamp.py b/tests/unit/util/test_timestamp.py index 62b32a2..452f2a5 100644 --- a/tests/unit/util/test_timestamp.py +++ b/tests/unit/util/test_timestamp.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- """Test timestamp conversion util functions""" -from datetime import datetime, timezone, timedelta +from datetime import datetime, timedelta, timezone + from sbws.util.timestamp import ( dt_obj_to_isodt_str, + is_old, unixts_to_dt_obj, unixts_to_isodt_str, unixts_to_str, - is_old, )
- isodt_str = "2018-05-23T12:55:04" dt_obj = datetime.strptime(isodt_str, "%Y-%m-%dT%H:%M:%S") unixts = int(dt_obj.replace(tzinfo=timezone.utc).timestamp()) diff --git a/tests/unit/util/test_timestamps.py b/tests/unit/util/test_timestamps.py index aef0501..8973f3d 100644 --- a/tests/unit/util/test_timestamps.py +++ b/tests/unit/util/test_timestamps.py @@ -3,10 +3,7 @@ from datetime import datetime, timedelta
from sbws.util.state import State -from sbws.util.timestamps import ( - DateTimeSeq, - DateTimeIntSeq, -) +from sbws.util.timestamps import DateTimeIntSeq, DateTimeSeq
def test_update_datetime_seq(conf): diff --git a/tests/unit/util/test_userquery.py b/tests/unit/util/test_userquery.py index 3313960..0558132 100644 --- a/tests/unit/util/test_userquery.py +++ b/tests/unit/util/test_userquery.py @@ -1,4 +1,5 @@ from unittest.mock import patch + from sbws.util.userquery import query_yes_no