mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
pytest: Migrate env to pyln-testing
This commit is contained in:
@@ -17,6 +17,7 @@ import sqlite3
|
|||||||
import string
|
import string
|
||||||
import struct
|
import struct
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@@ -36,22 +37,40 @@ LIGHTNINGD_CONFIG = OrderedDict({
|
|||||||
'disable-dns': None,
|
'disable-dns': None,
|
||||||
})
|
})
|
||||||
|
|
||||||
with open('config.vars') as configfile:
|
|
||||||
config = dict([(line.rstrip().split('=', 1)) for line in configfile])
|
|
||||||
|
|
||||||
DEVELOPER = os.getenv("DEVELOPER", config['DEVELOPER']) == "1"
|
def env(name, default=None):
|
||||||
EXPERIMENTAL_FEATURES = os.getenv("EXPERIMENTAL_FEATURES", config['EXPERIMENTAL_FEATURES']) == "1"
|
"""Access to environment variables
|
||||||
|
|
||||||
# Gossip can be slow without DEVELOPER.
|
Allows access to environment variables, falling back to config.vars (part
|
||||||
if DEVELOPER:
|
of c-lightning's `./configure` output), and finally falling back to a
|
||||||
DEFAULT_TIMEOUT = 60
|
default value.
|
||||||
|
|
||||||
|
"""
|
||||||
|
fname = 'config.vars'
|
||||||
|
if os.path.exists(fname):
|
||||||
|
lines = open(fname, 'r').readlines()
|
||||||
|
config = dict([(line.rstrip().split('=', 1)) for line in lines])
|
||||||
else:
|
else:
|
||||||
DEFAULT_TIMEOUT = 180
|
config = {}
|
||||||
|
|
||||||
TIMEOUT = int(os.getenv("TIMEOUT", str(DEFAULT_TIMEOUT)))
|
if name in os.environ:
|
||||||
VALGRIND = os.getenv("VALGRIND", config['VALGRIND']) == "1"
|
return os.environ[name]
|
||||||
SLOW_MACHINE = os.getenv("SLOW_MACHINE", "0") == "1"
|
elif name in config:
|
||||||
COMPAT = os.getenv("COMPAT", config['COMPAT']) == "1"
|
return config[name]
|
||||||
|
else:
|
||||||
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
VALGRIND = env("VALGRIND") == "1"
|
||||||
|
TEST_NETWORK = env("TEST_NETWORK", 'regtest')
|
||||||
|
DEVELOPER = env("DEVELOPER", "1") == "1"
|
||||||
|
TEST_DEBUG = env("TEST_DEBUG", "0") == "1"
|
||||||
|
SLOW_MACHINE = env("SLOW_MACHINE", "0") == "1"
|
||||||
|
TIMEOUT = int(env("TIMEOUT", 180 if SLOW_MACHINE else 60))
|
||||||
|
|
||||||
|
|
||||||
|
if TEST_DEBUG:
|
||||||
|
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
|
||||||
|
|
||||||
|
|
||||||
def wait_for(success, timeout=TIMEOUT):
|
def wait_for(success, timeout=TIMEOUT):
|
||||||
@@ -459,7 +478,7 @@ class LightningD(TailableProc):
|
|||||||
'lightning-dir': lightning_dir,
|
'lightning-dir': lightning_dir,
|
||||||
'addr': '127.0.0.1:{}'.format(port),
|
'addr': '127.0.0.1:{}'.format(port),
|
||||||
'allow-deprecated-apis': 'false',
|
'allow-deprecated-apis': 'false',
|
||||||
'network': config.get('TEST_NETWORK', 'regtest'),
|
'network': env('TEST_NETWORK', 'regtest'),
|
||||||
'ignore-fee-limits': 'false',
|
'ignore-fee-limits': 'false',
|
||||||
'bitcoin-rpcuser': BITCOIND_CONFIG['rpcuser'],
|
'bitcoin-rpcuser': BITCOIND_CONFIG['rpcuser'],
|
||||||
'bitcoin-rpcpassword': BITCOIND_CONFIG['rpcpassword'],
|
'bitcoin-rpcpassword': BITCOIND_CONFIG['rpcpassword'],
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ from collections import OrderedDict
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from ephemeral_port_reserve import reserve
|
from ephemeral_port_reserve import reserve
|
||||||
from lightning import LightningRpc
|
from lightning import LightningRpc
|
||||||
|
from pyln.testing.utils import TEST_NETWORK, SLOW_MACHINE, TIMEOUT, VALGRIND, DEVELOPER # noqa: F401
|
||||||
|
from pyln.testing.utils import env
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
@@ -19,7 +21,6 @@ import struct
|
|||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import sys
|
|
||||||
|
|
||||||
BITCOIND_CONFIG = {
|
BITCOIND_CONFIG = {
|
||||||
"regtest": 1,
|
"regtest": 1,
|
||||||
@@ -38,41 +39,8 @@ LIGHTNINGD_CONFIG = OrderedDict({
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def env(name, default=None):
|
EXPERIMENTAL_FEATURES = env("EXPERIMENTAL_FEATURES", "0") == "1"
|
||||||
"""Access to environment variables
|
|
||||||
|
|
||||||
Allows access to environment variables, falling back to config.vars (part
|
|
||||||
of c-lightning's `./configure` output), and finally falling back to a
|
|
||||||
default value.
|
|
||||||
|
|
||||||
"""
|
|
||||||
fname = 'config.vars'
|
|
||||||
if os.path.exists(fname):
|
|
||||||
lines = open(fname, 'r').readlines()
|
|
||||||
config = dict([(line.rstrip().split('=', 1)) for line in lines])
|
|
||||||
else:
|
|
||||||
config = {}
|
|
||||||
|
|
||||||
if name in os.environ:
|
|
||||||
return os.environ[name]
|
|
||||||
elif name in config:
|
|
||||||
return config[name]
|
|
||||||
else:
|
|
||||||
return default
|
|
||||||
|
|
||||||
|
|
||||||
VALGRIND = env("VALGRIND") == "1"
|
|
||||||
TEST_NETWORK = env("TEST_NETWORK", 'regtest')
|
|
||||||
DEVELOPER = env("DEVELOPER", "1") == "1"
|
|
||||||
TEST_DEBUG = env("TEST_DEBUG", "0") == "1"
|
|
||||||
SLOW_MACHINE = env("SLOW_MACHINE", "0") == "1"
|
|
||||||
COMPAT = env("COMPAT", "1") == "1"
|
COMPAT = env("COMPAT", "1") == "1"
|
||||||
EXPERIMENTAL_FEATURES = os.getenv("EXPERIMENTAL_FEATURES", "0") == "1"
|
|
||||||
TIMEOUT = int(env("TIMEOUT", 180 if SLOW_MACHINE else 60))
|
|
||||||
|
|
||||||
|
|
||||||
if TEST_DEBUG:
|
|
||||||
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
|
|
||||||
|
|
||||||
|
|
||||||
def wait_for(success, timeout=TIMEOUT):
|
def wait_for(success, timeout=TIMEOUT):
|
||||||
|
|||||||
Reference in New Issue
Block a user