test suite: data_dir, trash_dir fixups

This commit is contained in:
The MMGen Project 2026-09-11 14:10:56 +00:00
commit 6b4841e760
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
12 changed files with 45 additions and 41 deletions

View file

@ -285,7 +285,7 @@ class Config(Lockable):
exit_after = ''
resuming = False
skipping_deps = False
test_datadir = os.path.join('test', 'data_dir' + ('', '-α')[bool(os.getenv('MMGEN_DEBUG_UTF8'))])
test_datadir = os.path.join('test', 'tmp', 'data_dir')
mnemonic_entry_modes = {}

View file

@ -43,15 +43,14 @@ if os.path.exists(overlay_tree_dir):
rmtree(overlay_tree_dir, ignore_errors=True)
print(f'Removed {os.path.relpath(overlay_tree_dir)!r}')
from test.include.common import clean, set_globals
from test.include.common import clean, set_globals, trash_dir, trash_dir2
set_globals(cfg)
extra_dirs = [
Config.test_datadir,
os.path.join('test', 'trash'),
os.path.join('test', 'trash2')
]
trash_dir,
trash_dir2]
from test.cmdtest_d.include.cfg import cfgs
clean(cfgs, extra_dirs=extra_dirs)

View file

@ -25,13 +25,13 @@ def check_segwit_opts(proto):
if getattr(cfg, k) and m not in proto.mmtypes:
die(1, f'--{k.replace("_", "-")} option incompatible with {proto.cls_name}')
def create_shm_dir(data_dir, trash_dir):
def create_shm_dir(data_dir, trash_dir, trash_dir2):
# Laggy flash media can cause pexpect to fail, so create a temporary directory
# under '/dev/shm' and put datadir and tmpdirs here.
import shutil
from subprocess import run
if gc.platform in ('win32', 'darwin'):
for tdir in (data_dir, trash_dir):
for tdir in (data_dir, trash_dir, trash_dir2):
try:
os.listdir(tdir)
except:
@ -61,11 +61,12 @@ def create_shm_dir(data_dir, trash_dir):
except Exception as e:
die(2, f'Unable to create temporary directory in {tdir} ({e.args[0]})')
dest = os.path.join(shm_dir, os.path.basename(trash_dir))
os.mkdir(dest, 0o755)
for tdir in (trash_dir, trash_dir2):
dest = os.path.join(shm_dir, os.path.basename(tdir))
os.mkdir(dest, 0o755)
run(f'rm -rf {trash_dir}', shell=True, check=True)
os.symlink(dest, trash_dir)
run(f'rm -rf {tdir}', shell=True, check=True)
os.symlink(dest, tdir)
dest = os.path.join(shm_dir, os.path.basename(data_dir))
shutil.move(data_dir, dest) # data_dir was created by Config()
@ -90,6 +91,8 @@ from test.include.common import (
cmdtest_py_log_fn,
cmdtest_py_error_fn,
mk_tmpdir,
trash_dir,
trash_dir2,
stop_test_daemons)
try:
@ -179,10 +182,11 @@ data_dir = Config.test_datadir
# step 1: delete data_dir symlink in ./test;
if not po.user_opts.get('skip_deps'):
try:
os.unlink(data_dir)
except:
pass
for fn in (data_dir,):
try:
os.unlink(fn)
except:
pass
# step 2: opts.init will create new data_dir in ./test (if not po.user_opts['skip_deps'])
cfg = Config(opts_data=opts_data)
@ -212,11 +216,8 @@ if cfg.daemon_id and cfg.daemon_id in cfg.blacklisted_daemons.split():
die(1, f'cmdtest.py: daemon {cfg.daemon_id!r} blacklisted, exiting')
# step 3: move data_dir to /dev/shm and symlink it back to ./test:
trash_dir = os.path.join('test', 'trash')
trash_dir2 = os.path.join('test', 'trash2')
if not cfg.skipping_deps:
shm_dir = create_shm_dir(data_dir, trash_dir)
shm_dir = create_shm_dir(data_dir, trash_dir, trash_dir2)
check_segwit_opts(cfg._proto)

View file

@ -74,7 +74,7 @@ Ctrl_U = '\x15'
eth_inbound_addr = (28 * '0') + 'feedbeefcafe'
thorchain_router_addr_file = 'test/data_dir/thorchain_router_addr'
thorchain_router_addr_file = os.path.join(cfg.test_datadir, 'thorchain_router_addr')
def ok_msg():
if cfg.profile:

View file

@ -22,8 +22,9 @@ from ..include.common import (
sample_mn,
get_data_from_file,
read_from_file,
strip_ansi_escapes
)
strip_ansi_escapes,
trash_dir)
from .include.common import Ctrl_U, ref_dir
from .base import CmdTestBase
from .include.input import stealth_mnemonic_entry, user_dieroll_entry
@ -124,7 +125,7 @@ class CmdTestInput(CmdTestBase):
'--skip-cfg-file',
'--in-fmt=words',
'--out-fmt=words',
'--outdir=test/trash']
f'--outdir={trash_dir}']
mn = sample_mn['mmgen']['mn']
run_env = dict(os.environ)
run_env['MMGEN_TEST_SUITE'] = ''
@ -134,7 +135,7 @@ class CmdTestInput(CmdTestBase):
imsg(cp.stderr.decode().strip())
res = get_data_from_file(
self.cfg,
'test/trash/A773B05C[128].mmwords',
os.path.join(trash_dir, 'A773B05C[128].mmwords'),
silent = True).strip()
assert res == mn, f'{res} != {mn}'
return 'ok' if b'written to file' in cp.stderr else 'error'
@ -209,12 +210,12 @@ class CmdTestInput(CmdTestBase):
return t
def get_passphrase_cmdline(self):
with open('test/trash/pwfile', 'w') as fp:
with open(os.path.join(trash_dir, 'pwfile'), 'w') as fp:
fp.write('reference password\n')
t = self.spawn('test/misc/get_passphrase.py', [
'--usr-randchars=0',
'--label=MyLabel',
'--passwd-file=test/trash/pwfile',
'--passwd-file={}'.format(os.path.join(trash_dir, 'pwfile')),
'--hash-preset=1',
'seed'],
cmd_dir = '.')

View file

@ -39,6 +39,7 @@ from ..include.common import (
getrandnum,
getrandnum_range,
getrandhex,
trash_dir,
strip_ansi_escapes)
from .include.common import (
@ -382,7 +383,7 @@ class CmdTestMain(CmdTestBase, CmdTestShared):
self.tx_fee = {'btc':'90s', 'bch':'0.001', 'ltc':'0.01'}[self.coin]
self.txbump_fee = {'btc':'123s', 'bch':'567s', 'ltc':'12345s'}[self.coin]
self.unspent_data_file = joinpath('test', 'trash', 'unspent.json')
self.unspent_data_file = joinpath(trash_dir, 'unspent.json')
self.spawn_env['MMGEN_TEST_SUITE_BOGUS_UNSPENT_DATA'] = self.unspent_data_file
@property

View file

@ -26,7 +26,7 @@ import os
from mmgen.util import msg, capfirst
from mmgen.wallet import get_wallet_cls
from ..include.common import cmp_or_die, joinpath
from ..include.common import cmp_or_die, joinpath, trash_dir
from .include.common import (
pwfile,
ref_wallet_hash_preset,
@ -172,7 +172,7 @@ class CmdTestRef3Seed(CmdTestBase, CmdTestShared):
def ref_walletconv(self, ofmt, extra_args=[], re_pat=None):
wf = self.get_file_with_ext('mmdat')
pf = joinpath(self.tmpdir, pwfile)
t = self.spawn('mmgen-walletconv', extra_args+['-d', 'test/trash', '-o', ofmt, '-P'+pf, wf])
t = self.spawn('mmgen-walletconv', extra_args+['-d', trash_dir, '-o', ofmt, '-P'+pf, wf])
wcls = get_wallet_cls(fmt_code=ofmt)
fn = os.path.split(t.written_to_file(capfirst(wcls.desc)))[-1]
idx = int(self.test_name[-1]) - 1

View file

@ -25,7 +25,8 @@ from ..include.common import (
joinpath,
start_test_daemons,
stop_test_daemons,
cmp_or_die)
cmp_or_die,
trash_dir)
from .ref import CmdTestRef, CmdTestRefTX
from .base import CmdTestBase
@ -111,7 +112,7 @@ class CmdTestRefAltcoin(CmdTestRef, CmdTestBase):
start_test_daemons(proto.network_id)
t = self.spawn(
'mmgen-txsign',
['--outdir=test/trash', '--yes', f'--passwd-file={passfile}', dfl_words_file, txfile],
[f'--outdir={trash_dir}', '--yes', f'--passwd-file={passfile}', dfl_words_file, txfile],
no_passthru_opts = ['coin'],
extra_desc = f'{proto.coin}{token_desc} {proto.network}')
t.read()

View file

@ -16,7 +16,8 @@ from ..include.common import (
silence,
end_silence,
restart_test_daemons,
stop_test_daemons)
stop_test_daemons,
trash_dir2)
def get_obj(coin, network, msghash_type):
@ -54,7 +55,7 @@ async def do_test(network_id, chksum, msghash_type='raw'):
pumsg('\nTesting data creation:\n')
tmpdir = os.path.join('test', 'trash2')
tmpdir = trash_dir2
os.makedirs(tmpdir, exist_ok=True)

View file

@ -15,7 +15,7 @@ from mmgen.daemon import CoinDaemon
from mmgen.proto.xmr.rpc import MoneroRPCClient, MoneroWalletRPCClient
from mmgen.proto.xmr.daemon import MoneroWalletDaemon
from ..include.common import cfg, qmsg, vmsg, in_nix_environment, test_exec
from ..include.common import cfg, qmsg, vmsg, in_nix_environment, test_exec, trash_dir2
async def cfg_file_auth_test(cfg, d, bad_auth=False):
m = 'missing credentials' if bad_auth else f'credentials from {d.cfg_file}'
@ -246,8 +246,8 @@ class unit_tests:
cfg = cfg,
proto = proto,
test_suite = True,
wallet_dir = os.path.join('test', 'trash2'),
datadir = os.path.join('test', 'trash2', 'wallet_rpc'),
wallet_dir = trash_dir2,
datadir = os.path.join(trash_dir2, 'wallet_rpc'),
passwd = 'ut_rpc_passw0rd')
) for proto in (init_proto(cfg, 'xmr', network=network) for network in networks)]
@ -282,7 +282,7 @@ class unit_tests:
gmsg('OK')
import shutil
shutil.rmtree('test/trash2', ignore_errors=True)
os.makedirs('test/trash2/wallet_rpc')
shutil.rmtree(trash_dir2, ignore_errors=True)
os.makedirs(os.path.join(trash_dir2, 'wallet_rpc'))
await run()
return True

View file

@ -60,6 +60,9 @@ def set_globals(cfg):
def strip_ansi_escapes(s):
return re.sub('\x1b' + r'\[[;0-9]+?m', '', s)
trash_dir = os.path.join('test', 'tmp', 'trash')
trash_dir2 = os.path.join('test', 'tmp', 'trash2')
cmdtest_py_log_fn = 'cmdtest.py.log'
cmdtest_py_error_fn = 'cmdtest.py.err'
parity_dev_amt = 1606938044258990275541962092341162602522202993782792835301376

View file

@ -63,9 +63,6 @@ If no test is specified, all available tests are run
}
}
if os.path.islink(Config.test_datadir):
os.unlink(Config.test_datadir)
sys.argv.insert(1, '--skip-cfg-file')
cfg = Config(opts_data=opts_data)