options_helpers.py 792 B

123456789101112131415161718192021222324252627282930313233
  1. """Provides helper classes for testing option handling in pip
  2. """
  3. import os
  4. from pip._internal.cli import cmdoptions
  5. from pip._internal.cli.base_command import Command
  6. from pip._internal.commands import commands_dict
  7. class FakeCommand(Command):
  8. name = 'fake'
  9. summary = name
  10. def main(self, args):
  11. index_opts = cmdoptions.make_option_group(
  12. cmdoptions.index_group,
  13. self.parser,
  14. )
  15. self.parser.add_option_group(index_opts)
  16. return self.parse_args(args)
  17. class AddFakeCommandMixin(object):
  18. def setup(self):
  19. self.environ_before = os.environ.copy()
  20. commands_dict[FakeCommand.name] = FakeCommand
  21. def teardown(self):
  22. os.environ = self.environ_before
  23. commands_dict.pop(FakeCommand.name)