Skip to content
Snippets Groups Projects

Issue216: Revamp test support code

Merged juga requested to merge github/fork/juga0/issue216 into master

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

Approval is optional

Merged by avatar (Jan 10, 2025 7:10pm UTC)

Merge details

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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:
  • Author Owner

    Created by: pastly

    I think we can avoid this change. See elsewhere for suggested change to _PseudoArguments.

  • juga
    juga @juga started a thread on commit fedbac24
  • 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):
    • Author Owner

      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 its main(), we can do the following in order to be able to avoid the getattr() and go back to args.error_types.

      args.add_args(error_types=False)
  • juga
    juga @juga started a thread on commit fedbac24
  • 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:
    • Author Owner

      Created by: juga0

      i changed that to if hasattr(args, 'error_types') before i pushed, but forgot to commit :)

  • juga
    juga @juga started a thread on commit fedbac24
  • 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):
    • Author Owner

      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 with config.py

  • Author Owner

    Created by: juga0

    So, i'd propose i leave if args.error_types:, and add , error_types=False in our conftest.py args. We'll remember we need to add new args there when we run in AttributeError exceptions

  • Author Owner

    Created by: juga0

    (or somewhere else in the code with setattr)

  • Author Owner

    Created by: pastly

    After thinking about it some more, I've decided I'm fine with the code the way it is. Merging.

  • Please register or sign in to reply
    Loading