ts_base.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2019 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. ts_base.py: Base class for the test.py test suite
  20. """
  21. import os
  22. from mmgen.globalvars import g
  23. from mmgen.opts import opt
  24. from test.common import *
  25. from test.test_py_d.common import *
  26. class TestSuiteBase(object):
  27. 'initializer class for the test.py test suite'
  28. passthru_opts = ()
  29. networks = ()
  30. segwit_opts_ok = False
  31. def __init__(self,trunner,cfgs,spawn):
  32. self.tr = trunner
  33. self.cfgs = cfgs
  34. self.spawn = spawn
  35. self.have_dfl_wallet = False
  36. self.usr_rand_chars = (5,30)[bool(opt.usr_random)]
  37. self.usr_rand_arg = '-r{}'.format(self.usr_rand_chars)
  38. self.altcoin_pfx = '' if g.proto.base_coin == 'BTC' else '-'+g.proto.base_coin
  39. self.tn_ext = ('','.testnet')[g.testnet]
  40. d = {'bch':'btc','btc':'btc','ltc':'ltc'}
  41. self.fork = d[g.coin.lower()] if g.coin.lower() in d else None
  42. @property
  43. def tmpdir(self):
  44. return os.path.join('test','tmp{}{}'.format(self.tmpdir_num,'-α' if g.debug_utf8 else ''))
  45. @property
  46. def segwit_mmtype(self):
  47. return ('segwit','bech32')[bool(opt.bech32)] if self.segwit else None
  48. @property
  49. def segwit_arg(self):
  50. return ['--type=' + self.segwit_mmtype] if self.segwit_mmtype else []
  51. def get_file_with_ext(self,ext,**kwargs):
  52. return get_file_with_ext(self.tmpdir,ext,**kwargs)
  53. def read_from_tmpfile(self,fn,binary=False):
  54. return read_from_file(os.path.join(self.tmpdir,fn),binary=binary)
  55. def write_to_tmpfile(self,fn,data,binary=False):
  56. return write_to_file(os.path.join(self.tmpdir,fn),data,binary=binary)
  57. def skip_for_win(self):
  58. if g.platform == 'win':
  59. msg("Skipping test '{}': not supported on MSys2 platform".format(self.test_name))
  60. return True
  61. else:
  62. return False