diff --git a/test/test_circle.py b/test/test_circle.py index 4a31342..e7524fa 100644 --- a/test/test_circle.py +++ b/test/test_circle.py @@ -5,6 +5,12 @@ import time from typing import List import unittest +from test.testing_common import ( + test_graphs_paths, + SLEEP_SEC_AFTER_REBALANCING, + TestNetwork, +) + from lndmanage.lib.listings import ListChannels from lndmanage.lib.rebalance import Rebalancer from lndmanage.lib.exceptions import ( @@ -15,12 +21,6 @@ from lndmanage.lib.exceptions import ( OurNodeFailure, ) -from test.testing_common import ( - test_graphs_paths, - SLEEP_SEC_AFTER_REBALANCING, - TestNetwork, -) - from lndmanage import settings # needed for side effect configuration diff --git a/test/test_fee_setting.py b/test/test_fee_setting.py index e183363..b9ddf15 100644 --- a/test/test_fee_setting.py +++ b/test/test_fee_setting.py @@ -2,9 +2,9 @@ from unittest import TestCase import sys import logging -from lndmanage.lib.fee_setting import delta_demand, delta_min, optimization_parameters +from test import testing_common -import testing_common +from lndmanage.lib.fee_setting import delta_demand, delta_min, optimization_parameters testing_common.logger.addHandler(logging.StreamHandler(sys.stdout)) diff --git a/test/test_openchannels.py b/test/test_openchannels.py index 93b43ab..11ccb5c 100644 --- a/test/test_openchannels.py +++ b/test/test_openchannels.py @@ -3,13 +3,13 @@ import asyncio import time from unittest import TestCase -from lndmanage.lib import openchannels - from test.testing_common import ( test_graphs_paths, TestNetwork, ) +from lndmanage.lib import openchannels + def confirm_transactions(testnet): for _ in range(6): diff --git a/test/test_rebalance.py b/test/test_rebalance.py index 2df73e3..4d4b725 100644 --- a/test/test_rebalance.py +++ b/test/test_rebalance.py @@ -3,16 +3,16 @@ import asyncio import time from typing import Optional -from lndmanage.lib.rebalance import Rebalancer -from lndmanage.lib.ln_utilities import local_balance_to_unbalancedness -from lndmanage.lib.exceptions import NoRebalanceCandidates - from test.testing_common import ( test_graphs_paths, SLEEP_SEC_AFTER_REBALANCING, TestNetwork ) +from lndmanage.lib.rebalance import Rebalancer +from lndmanage.lib.ln_utilities import local_balance_to_unbalancedness +from lndmanage.lib.exceptions import NoRebalanceCandidates + class RebalanceTest(TestNetwork): """ diff --git a/test/testing_common.py b/test/testing_common.py index be8fc24..01e2e41 100644 --- a/test/testing_common.py +++ b/test/testing_common.py @@ -3,6 +3,21 @@ import os import shutil from unittest import TestCase +# testing base folder +test_dir = os.path.dirname(os.path.realpath(__file__)) +bin_dir = os.path.join(test_dir, 'bin') +graph_definitions_dir = os.path.join(test_dir, 'graph_definitions') +test_data_dir = os.path.join(test_dir, 'test_data') + +# set lndmanage_home path to be in the test_data folder and make sure the +# directory exists +lndmanage_home = os.path.join(test_data_dir, 'lndmanage') +os.makedirs(lndmanage_home, exist_ok=True) + +# create empty config and set env var to not trigger error when importing settings +open(os.path.join(lndmanage_home, 'config.ini'), 'a').close() +os.environ.setdefault('LNDMANAGE_HOME', lndmanage_home) + from lnregtest.lib.network import Network from lndmanage.lib.node import LndNode @@ -17,17 +32,6 @@ settings.CACHING_RETENTION_MINUTES = 0 # constants for testing SLEEP_SEC_AFTER_REBALANCING = 2 -# testing base folder -test_dir = os.path.dirname(os.path.realpath(__file__)) -bin_dir = os.path.join(test_dir, 'bin') -graph_definitions_dir = os.path.join(test_dir, 'graph_definitions') -test_data_dir = os.path.join(test_dir, 'test_data') - -# set lndmanage_home path to be in the test_data folder and make sure the -# folder exists -lndmanage_home = os.path.join(test_data_dir, 'lndmanage') -os.makedirs(lndmanage_home, exist_ok=True) - test_graphs_paths = { 'star_ring_3_liquid': os.path.join( graph_definitions_dir, 'star_ring_3_liquid.py'),