From ff4ec64900231ce4f5426c2c0fc8a5f136dac1eb Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 14 Nov 2023 16:01:43 +0000 Subject: [PATCH] MSYS2 testing fixes --- mmgen/color.py | 11 +++++++++-- mmgen/fileutil.py | 13 +++++++------ setup.cfg | 2 +- test/cmdtest_py_d/ct_main.py | 9 +++++++-- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/mmgen/color.py b/mmgen/color.py index 19fe85d2..1c8019fc 100755 --- a/mmgen/color.py +++ b/mmgen/color.py @@ -84,8 +84,15 @@ def init_color(num_colors='auto'): if num_colors == 'auto': import os - t = os.getenv('TERM') - num_colors = 256 if (t and t.endswith('256color')) or get_terminfo_colors() == 256 else 16 + if sys.platform == 'win32': + # Force 256-color for MSYS2: terminal supports it, however infocmp reports 8-color. + # We also avoid spawning a subprocess, leading to a subsequent OSError 22 when testing + # with pexpect spawn. + num_colors = 256 + elif (t := os.getenv('TERM')) and t.endswith('256color'): + num_colors = 256 + else: + num_colors = get_terminfo_colors() or 16 reset = '\033[0m' if num_colors == 0: diff --git a/mmgen/fileutil.py b/mmgen/fileutil.py index ce470f6f..c004a9c4 100755 --- a/mmgen/fileutil.py +++ b/mmgen/fileutil.py @@ -38,12 +38,13 @@ def check_or_create_dir(path): os.listdir(path) except: if os.getenv('MMGEN_TEST_SUITE'): - from subprocess import run - run([ - ('rm' if sys.platform == 'win32' else '/bin/rm'), - '-rf', - path ]) - set_vt100() + if os.path.exists(path): # path is a link or regular file + from subprocess import run + run([ + ('rm' if sys.platform == 'win32' else '/bin/rm'), + '-rf', + path ]) + set_vt100() try: os.makedirs(path,0o700) except: diff --git a/setup.cfg b/setup.cfg index 66cb4c0a..59756afd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ classifiers = Development Status :: 5 - Production/Stable [options] -python_requires = >=3.7 +python_requires = >=3.8 include_package_data = True install_requires = diff --git a/test/cmdtest_py_d/ct_main.py b/test/cmdtest_py_d/ct_main.py index 9aec0c67..b2512921 100755 --- a/test/cmdtest_py_d/ct_main.py +++ b/test/cmdtest_py_d/ct_main.py @@ -309,8 +309,6 @@ class CmdTestMain(CmdTestBase,CmdTestShared): CmdTestBase.__init__(self,trunner,cfgs,spawn) if trunner is None or self.proto.coin.lower() not in self.networks: return - self.rpc = async_run(rpc_init(cfg,self.proto)) - self.lbl_id = ('account','label')['label_api' in self.rpc.caps] if self.proto.coin in ('BTC','BCH','LTC'): self.tx_fee = {'btc':'0.0001','bch':'0.001','ltc':'0.01'}[self.proto.coin.lower()] self.txbump_fee = {'btc':'123s','bch':'567s','ltc':'12345s'}[self.proto.coin.lower()] @@ -318,6 +316,13 @@ class CmdTestMain(CmdTestBase,CmdTestShared): self.unspent_data_file = joinpath('test','trash','unspent.json') self.spawn_env['MMGEN_BOGUS_UNSPENT_DATA'] = self.unspent_data_file + @property + def lbl_id(self): + if not hasattr(self,'_lbl_id'): + rpc = async_run(rpc_init(cfg,self.proto)) + self._lbl_id = ('account','label')['label_api' in rpc.caps] + return self._lbl_id + def _get_addrfile_checksum(self,display=False): addrfile = self.get_file_with_ext('addrs') from mmgen.addrlist import AddrList