Issue216: Revamp test support code
Created by: juga0
Fixes #216 (closed) 3 first commits would fix #209 (closed). The improvement is not that much. It fixes part of #170 (closed), we could solve what is missing in other PRs. Sorry for the big and not detailed commits.
Merge request reports
Activity
Filter activity
130 130 fastest_transfer/1024)) 131 131 print('Results come from', first, 'to', last, 'over a period of', 132 132 duration) 133 if args.error_types: 133 if getattr(args, 'error_types', False) is True: 2 from tempfile import TemporaryDirectory 3 from sbws.util.parser import create_parser 4 from sbws.util.config import get_config 5 from sbws.util.stem import launch_tor 6 import sbws.core.init 7 4 import os 8 5 6 from sbws.core import init 7 from sbws.lib.circuitbuilder import GapsCircuitBuilder as CB 8 from sbws.lib.destination import DestinationList 9 from sbws.lib.relaylist import RelayList 10 from sbws.util.config import _get_default_config 11 from sbws.util.stem import launch_tor 12 13 14 class _PseudoArguments(argparse.Namespace): Created by: pastly
I think we should add a function to this class that adds arbitrary attributes after the object has been created.
For example, when we want to test
sbws.core.stats
and call itsmain()
, we can do the following in order to be able to avoid thegetattr()
and go back toargs.error_types
.args.add_args(error_types=False)
130 130 fastest_transfer/1024)) 131 131 print('Results come from', first, 'to', last, 'over a period of', 132 132 duration) 133 if args.error_types: 133 if getattr(args, 'error_types', False) is True: 2 from tempfile import TemporaryDirectory 3 from sbws.util.parser import create_parser 4 from sbws.util.config import get_config 5 from sbws.util.stem import launch_tor 6 import sbws.core.init 7 4 import os 8 5 6 from sbws.core import init 7 from sbws.lib.circuitbuilder import GapsCircuitBuilder as CB 8 from sbws.lib.destination import DestinationList 9 from sbws.lib.relaylist import RelayList 10 from sbws.util.config import _get_default_config 11 from sbws.util.stem import launch_tor 12 13 14 class _PseudoArguments(argparse.Namespace): Created by: juga0
hmm, i could add:
def add_arg(self, arg): setattr(self, arg)
but then why just not using
setattr
In the tests i could just initialize the args with:
args = _PseudoArguments(directory=sbwshome_dir, output=sbwshome_dir, scale=False, log_level='debug', error_types=False)
no need for
add_arg
In non-tests, you ensure all the possible args are present withconfig.py
Please register or sign in to reply