minor changes, whitespace

This commit is contained in:
The MMGen Project 2021-10-02 17:54:11 +00:00
commit ea5eedcff3
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
6 changed files with 66 additions and 51 deletions

View file

@ -41,16 +41,23 @@ _colors = {
'yelbg': ( (232,229), (30,103) ),
}
_reset = ''
for _c in _colors:
_e = _colors[_c]
globals()['_256_'+_c] = '\033[38;5;{};1m'.format(_e[0]) if type(_e[0]) == int \
else '\033[38;5;{};48;5;{};1m'.format(*_e[0])
globals()['_16_'+_c] = '\033[{}m'.format(_e[1][0]) if _e[1][1] == 0 \
else '\033[{};{}m'.format(*_e[1])
globals()['_clr_'+_c] = ''; _reset = ''
exec('def {c}(s): return _clr_{c}+s+_reset'.format(c=_c))
globals()['_256_'+_c] = (
'\033[38;5;{};1m'.format(_e[0]) if type(_e[0]) == int else
'\033[38;5;{};48;5;{};1m'.format(*_e[0])
)
globals()['_16_'+_c] = (
'\033[{}m'.format(_e[1][0]) if _e[1][1] == 0 else
'\033[{};{}m'.format(*_e[1])
)
globals()['_clr_'+_c] = ''
exec(f'{_c} = lambda s: _clr_{_c}+s+_reset')
def nocolor(s): return s
def nocolor(s):
return s
def set_vt100():
'hack to put term into VT100 mode under MSWin'
@ -84,16 +91,18 @@ def get_terminfo_colors(term=None):
def init_color(num_colors='auto'):
assert num_colors in ('auto',8,16,256)
globals()['_reset'] = '\033[0m'
import os
t = os.getenv('TERM')
if num_colors in (8,16):
pfx = '_16_'
elif num_colors == 256 or (t and t.endswith('256color')) or get_terminfo_colors() == 256:
pfx = '_256_'
else:
pfx = '_16_'
import os
t = os.getenv('TERM')
if num_colors == 256 or (t and t.endswith('256color')) or get_terminfo_colors() == 256:
pfx = '_256_'
else:
pfx = '_16_'
for c in _colors:
globals()['_clr_'+c] = globals()[pfx+c]

View file

@ -1,25 +1,26 @@
#!/usr/bin/env python3
# Import as few modules and define as few names as possible at global level before exec'ing the
# file, as all names will be seen by the exec'ed file. To prevent name collisions, all names
# file, as all names will be seen by the exec'ed code. To prevent name collisions, all names
# defined here should begin with 'traceback_run_'
import sys,os,time
def traceback_get_colors():
def traceback_run_get_colors():
from collections import namedtuple
return namedtuple('colors',['red','yellow','blue'])(*[
return namedtuple('colors',['red','green','yellow','blue'])(*[
(lambda s:s) if os.getenv('MMGEN_DISABLE_COLOR') else
(lambda s,n=n:f'\033[{n};1m{s}\033[0m' )
for n in (31,33,34) ])
for n in (31,32,33,34) ])
def traceback_run_init():
import os
sys.path[0] = 'test' if os.path.dirname(sys.argv[1]) == 'test' else '.'
if 'TMUX' in os.environ: del os.environ['TMUX']
os.environ['MMGEN_TRACEBACK'] = '1'
os.environ['PYTHONPATH'] = '.'
if 'TMUX' in os.environ:
del os.environ['TMUX']
of = 'my.err'
try: os.unlink(of)
@ -39,12 +40,12 @@ def traceback_run_process_exception():
if exc.startswith('SystemExit:'):
lines.pop()
c = traceback_get_colors()
c = traceback_run_get_colors()
sys.stdout.write('{}{}'.format(c.yellow(''.join(lines)),c.red(exc)))
open(traceback_run_outfile,'w').write(''.join(lines+[exc]))
traceback_run_outfile = traceback_run_init()
traceback_run_outfile = traceback_run_init() # sets sys.path[0]
traceback_run_tstart = time.time()
try:
@ -60,5 +61,5 @@ except Exception as e:
retval = e.mmcode if hasattr(e,'mmcode') else e.code if hasattr(e,'code') else 1
sys.exit(retval)
c = traceback_get_colors()
c = traceback_run_get_colors()
sys.stderr.write(c.blue('Runtime: {:0.5f} secs\n'.format(time.time() - traceback_run_tstart)))

View file

@ -46,6 +46,7 @@ packages =
mmgen.altcoins.eth
mmgen.altcoins.eth.pyethereum
mmgen.altcoins.eth.rlp
mmgen.altcoins.eth.rlp.sedes
scripts =
cmds/mmgen-addrgen

View file

@ -83,8 +83,7 @@ def getrandnum_range(nbytes,rn_max):
return rn
def getrandstr(num_chars,no_space=False):
n,m = 95,32
if no_space: n,m = 94,33
n,m = (94,33) if no_space else (95,32)
return ''.join([chr(i%n+m) for i in list(os.urandom(num_chars))])
def get_data_dir():

View file

@ -1,6 +1,5 @@
#!/usr/bin/env python3
from mmgen.util import msg
from mmgen.common import *
cmd_args = opts.init()

View file

@ -10,11 +10,6 @@ elif uname -a | grep -q 'MSYS'; then
SUDO='' MSYS2=1;
fi
[ "$MMGEN_DISABLE_COLOR" ] || {
RED="\e[31;1m" GREEN="\e[32;1m" YELLOW="\e[33;1m" BLUE="\e[34;1m" MAGENTA="\e[35;1m" CYAN="\e[36;1m"
RESET="\e[0m"
}
trap 'echo -e "${GREEN}Exiting at user request$RESET"; exit' INT
umask 0022
@ -22,6 +17,7 @@ umask 0022
export MMGEN_TEST_SUITE=1
export MMGEN_NO_LICENSE=1
export PYTHONPATH=.
test_py='test/test.py -n'
objtest_py='test/objtest.py'
objattrtest_py='test/objattrtest.py'
@ -49,23 +45,23 @@ do
case "$OPT" in
h) printf " %-16s Test MMGen release\n" "${PROGNAME}:"
echo " USAGE: $PROGNAME [options] [tests or test group]"
echo " OPTIONS: '-h' Print this help message"
echo " '-A' Skip tests requiring altcoin modules or daemons"
echo " '-b' Buffer keypresses for all invocations of 'test/test.py'"
echo " '-C' Run tests in coverage mode"
echo " '-f' Speed up the tests by using fewer rounds"
echo " '-F' Reduce rounds even further"
echo " '-i' Create and install Python package, then run tests. A branch"
echo " must be supplied as a parameter"
echo " '-I' Like '-i', but install the package without running the tests"
echo " '-l' List the test name symbols"
echo " '-N' Pass the --no-timings switch to test/test.py"
echo " '-O' Use pexpect.spawn rather than popen_spawn for applicable tests"
echo " '-p' Pause between tests"
echo " '-t' Print the tests without running them"
echo " '-v' Run test/test.py with '--exact-output' and other commands with"
echo " '--verbose' switch"
echo " '-V' Run test/test.py and other commands with '--verbose' switch"
echo " OPTIONS: -h Print this help message"
echo " -A Skip tests requiring altcoin modules or daemons"
echo " -b Buffer keypresses for all invocations of 'test/test.py'"
echo " -C Run tests in coverage mode"
echo " -f Speed up the tests by using fewer rounds"
echo " -F Reduce rounds even further"
echo " -i BRANCH Create and install Python package from cloned BRANCH, then"
echo " run tests in installed package"
echo " -I BRANCH Like '-i', but install the package without running the tests"
echo " -l List the test name symbols"
echo " -N Pass the --no-timings switch to test/test.py"
echo " -O Use pexpect.spawn rather than popen_spawn where applicable"
echo " -p Pause between tests"
echo " -t Print the tests without running them"
echo " -v Run test/test.py with '--exact-output' and other commands"
echo " with '--verbose' switch"
echo " -V Run test/test.py and other commands with '--verbose' switch"
echo
echo " AVAILABLE TESTS:"
echo " obj - data objects"
@ -146,6 +142,11 @@ do
esac
done
[ "$MMGEN_DISABLE_COLOR" ] || {
RED="\e[31;1m" GREEN="\e[32;1m" YELLOW="\e[33;1m" BLUE="\e[34;1m" MAGENTA="\e[35;1m" CYAN="\e[36;1m"
RESET="\e[0m"
}
[ "$MSYS2" -a ! "$FAST" ] && tooltest2_py+=' --fork'
[ "$EXACT_OUTPUT" -o "$VERBOSE" ] || objtest_py+=" -S"
@ -541,6 +542,7 @@ prompt_skip() {
}
run_tests() {
[ "$LIST_CMDS" ] || echo "Running tests: $1"
for t in $1; do
if [ "$SKIP_ALT_DEP" ]; then
ok=$(for a in $noalt_tests; do if [ $t == $a ]; then echo 'ok'; fi; done)
@ -572,10 +574,14 @@ check_args() {
}
check_args
[ "$LIST_CMDS" ] || echo "Running tests: $tests"
START=$(date +%s)
run_tests "$tests"
TIME=$(($(date +%s)-START))
MS=$(printf %02d:%02d $((TIME/60)) $((TIME%60)))
[ "$LIST_CMDS" ] || echo -e "${GREEN}All OK. Total elapsed time: $MS$RESET"
start_time=$(date +%s)
run_tests "$tests"
elapsed=$(($(date +%s)-start_time))
elapsed_fmt=$(printf %02d:%02d $((elapsed/60)) $((elapsed%60)))
[ "$LIST_CMDS" ] || {
echo -e "${GREEN}All OK. Total elapsed time: $elapsed_fmt$RESET"
}