From a1a5fa396e7d6978db87b07db9a4b176cd76b8e3 Mon Sep 17 00:00:00 2001 From: "Jesse P. Johnson" Date: Sun, 15 Jan 2023 09:46:50 -0500 Subject: [PATCH] tests: refactor to resolve deprecated pytest features --- tests/cli.py | 2 +- tests/collection.py | 20 ++++++++++---------- tests/completion.py | 4 ++-- tests/concurrency.py | 4 ++-- tests/context.py | 6 +++--- tests/executor.py | 2 +- tests/loader.py | 2 +- tests/parser_context.py | 8 ++++---- tests/parser_parser.py | 6 +++--- tests/program.py | 2 +- tests/runners.py | 14 +++++++------- tests/task.py | 10 +++++----- 12 files changed, 40 insertions(+), 40 deletions(-) diff --git a/tests/cli.py b/tests/cli.py index eef8fc346..6382b285c 100644 --- a/tests/cli.py +++ b/tests/cli.py @@ -8,7 +8,7 @@ class CLIParsing: High level parsing tests """ - def setup(self): + def setup_method(self): @task(positional=[], iterable=["my_list"], incrementable=["verbose"]) def my_task( c, diff --git a/tests/collection.py b/tests/collection.py index 558826098..cd0f19508 100644 --- a/tests/collection.py +++ b/tests/collection.py @@ -102,7 +102,7 @@ def task3(c): submeh = Collection("submeh", task3) return Collection("meh", task1, task2, submeh) - def setup(self): + def setup_method(self): self.c = self._meh() def repr_(self): @@ -148,11 +148,11 @@ def foo(c): assert not Collection(foo=Collection()) class from_module: - def setup(self): + def setup_method(self): self.c = Collection.from_module(load("integration")) class parameters: - def setup(self): + def setup_method(self): self.mod = load("integration") self.from_module = Collection.from_module @@ -232,7 +232,7 @@ def returns_unique_Collection_objects_for_same_input_module(self): assert c3 is not c4 class explicit_root_ns: - def setup(self): + def setup_method(self): mod = load("explicit_root") mod.ns.configure( { @@ -278,7 +278,7 @@ def docstring_still_copied_from_module(self): assert self.changed.__doc__.strip() == expected class add_task: - def setup(self): + def setup_method(self): self.c = Collection() def associates_given_callable_with_given_name(self): @@ -350,7 +350,7 @@ def biz(c): assert self.c[x] is self.c["biz"] class add_collection: - def setup(self): + def setup_method(self): self.c = Collection() def adds_collection_as_subcollection_of_self(self): @@ -394,7 +394,7 @@ def raises_ValueError_on_multiple_defaults(self): class getitem: "__getitem__" - def setup(self): + def setup_method(self): self.c = Collection() def finds_own_tasks_by_name(self): @@ -447,7 +447,7 @@ def ValueError_for_empty_subcol_task_name_and_no_default(self): self.c["whatever"] class to_contexts: - def setup(self): + def setup_method(self): @task def mytask(c, text, boolean=False, number=5): print(text) @@ -598,7 +598,7 @@ def exposes_aliases(self): assert "mytask27" in self.aliases class task_names: - def setup(self): + def setup_method(self): self.c = Collection.from_module(load("explicit_root")) def returns_all_task_names_including_subtasks(self): @@ -614,7 +614,7 @@ def includes_aliases_and_defaults_as_values(self): class configuration: "Configuration methods" - def setup(self): + def setup_method(self): self.root = Collection() self.task = Task(_func, name="task") diff --git a/tests/completion.py b/tests/completion.py index 9b23e1b4c..10369d0c7 100644 --- a/tests/completion.py +++ b/tests/completion.py @@ -32,13 +32,13 @@ class CompletionScriptPrinter: Printing the completion script """ - def setup(self): + def setup_method(self): self.prev_cwd = os.getcwd() # Chdir to system root to (hopefully) avoid any tasks.py. This will # prove that --print-completion-script works w/o nearby tasks. os.chdir(ROOT) - def teardown(self): + def teardown_method(self): os.chdir(self.prev_cwd) def only_accepts_certain_shells(self): diff --git a/tests/concurrency.py b/tests/concurrency.py index d72933e33..7110e6818 100644 --- a/tests/concurrency.py +++ b/tests/concurrency.py @@ -6,7 +6,7 @@ # TODO: rename class ExceptionHandlingThread_: class via_target: - def setup(self): + def setup_method(self): def worker(q): q.put(7) @@ -48,7 +48,7 @@ def exhibits_is_dead_flag(self): assert not t.is_dead class via_subclassing: - def setup(self): + def setup_method(self): class MyThread(EHThread): def __init__(self, *args, **kwargs): self.queue = kwargs.pop("queue") diff --git a/tests/context.py b/tests/context.py index aad4fd7b6..0b415e681 100644 --- a/tests/context.py +++ b/tests/context.py @@ -63,7 +63,7 @@ def sudo(self): class configuration_proxy: "Dict-like proxy for self.config" - def setup(self): + def setup_method(self): config = Config(defaults={"foo": "bar", "biz": {"baz": "boz"}}) self.c = Context(config=config) @@ -133,7 +133,7 @@ def update(self): assert self.c.biz.otherbaz == "otherboz" class cwd: - def setup(self): + def setup_method(self): self.c = Context() def simple(self): @@ -401,7 +401,7 @@ def sudo_password_kwarg_wins_over_config(self): self._expect_responses(expected, config=config, kwargs=kwargs) class auto_response_merges_with_other_responses: - def setup(self): + def setup_method(self): class DummyWatcher(StreamWatcher): def submit(self, stream): pass diff --git a/tests/executor.py b/tests/executor.py index 21d3ba79a..7ce661770 100644 --- a/tests/executor.py +++ b/tests/executor.py @@ -13,7 +13,7 @@ class Executor_: - def setup(self): + def setup_method(self): self.task1 = Task(Mock(return_value=7)) self.task2 = Task(Mock(return_value=10), pre=[self.task1]) self.task3 = Task(Mock(), pre=[self.task1]) diff --git a/tests/loader.py b/tests/loader.py index 1d585dd70..7642c703c 100644 --- a/tests/loader.py +++ b/tests/loader.py @@ -79,7 +79,7 @@ def find(self, name): class FilesystemLoader_: - def setup(self): + def setup_method(self): self.loader = FSLoader(start=support) def discovery_start_point_defaults_to_cwd(self): diff --git a/tests/parser_context.py b/tests/parser_context.py index a16406e8f..567d40adc 100644 --- a/tests/parser_context.py +++ b/tests/parser_context.py @@ -28,7 +28,7 @@ def may_give_arg_list_at_init_time(self): # tests within 'add_arg'. Some of this behavior is technically driven by # add_arg. class args: - def setup(self): + def setup_method(self): self.c = Context( args=( Argument("foo"), @@ -56,7 +56,7 @@ def argument_attr_names_appear_in_args_but_not_flags(self): assert "wat" not in self.c.flags class add_arg: - def setup(self): + def setup_method(self): self.c = Context() def can_take_Argument_instance(self): @@ -134,7 +134,7 @@ def positional_arg_modifications_affect_args_copy(self): class deepcopy: "__deepcopy__" - def setup(self): + def setup_method(self): self.arg = Argument("--boolean") self.orig = Context( name="mytask", args=(self.arg,), aliases=("othername",) @@ -157,7 +157,7 @@ def modifications_to_copied_arguments_do_not_touch_originals(self): assert not self.arg.value class help_for: - def setup(self): + def setup_method(self): # Normal, non-task/collection related Context self.vanilla = Context( args=(Argument("foo"), Argument("bar", help="bar the baz")) diff --git a/tests/parser_parser.py b/tests/parser_parser.py index 1751bfd4c..c750fd8c7 100644 --- a/tests/parser_parser.py +++ b/tests/parser_parser.py @@ -168,7 +168,7 @@ def clones_noninitial_contexts(self): assert a2.value == "val" class parsing_errors: - def setup(self): + def setup_method(self): self.p = Parser([Context(name="foo", args=[Argument("bar")])]) def missing_flag_values_raise_ParseError(self): @@ -280,7 +280,7 @@ def handles_multiple_boolean_flags_per_context(self): assert a.bar.value is True class optional_arg_values: - def setup(self): + def setup_method(self): self.parser = self._parser() def _parser(self, arguments=None): @@ -525,7 +525,7 @@ def other_tokens_afterwards_raise_parse_errors(self): class ParseResult_: "ParseResult" - def setup(self): + def setup_method(self): self.context = Context( "mytask", args=(Argument("foo", kind=str), Argument("bar")) ) diff --git a/tests/program.py b/tests/program.py index 64bfdc2c3..2a6d4f01c 100644 --- a/tests/program.py +++ b/tests/program.py @@ -1193,7 +1193,7 @@ def invalid_namespaces_exit_with_message(self): ) class json: - def setup(self): + def setup_method(self): # Stored expected data as an actual JSON file cuz it's big # & looks like crap if inlined. Plus by round-tripping it # we remove the pretty-printing. Win-win? diff --git a/tests/runners.py b/tests/runners.py index 81236b48c..2086f57a1 100644 --- a/tests/runners.py +++ b/tests/runners.py @@ -84,7 +84,7 @@ def _expect_platform_shell(shell): assert shell == "/bin/bash" -def make_tcattrs(cc_is_ints=True, echo=False): +def _make_tcattrs(cc_is_ints=True, echo=False): # Set up the control character sub-array; it's technically platform # dependent so we need to be dynamic. # NOTE: setting this up so we can test both potential values for @@ -665,7 +665,7 @@ def similar_to_just_the_result_repr(self): assert repr(e) == expected.format(_) class UnexpectedExit_str: - def setup(self): + def setup_method(self): def lines(prefix): prefixed = "\n".join( "{} {}".format(prefix, x) for x in range(1, 26) @@ -1238,7 +1238,7 @@ class character_buffered_stdin: @skip_if_windows @patch("invoke.terminals.tty") def setcbreak_called_on_tty_stdins(self, mock_tty, mock_termios): - mock_termios.tcgetattr.return_value = make_tcattrs(echo=True) + mock_termios.tcgetattr.return_value = _make_tcattrs(echo=True) self._run(_) mock_tty.setcbreak.assert_called_with(sys.stdin) @@ -1269,7 +1269,7 @@ def tty_stdins_have_settings_restored_by_default( ): # Get already-cbroken attrs since that's an easy way to get the # right format/layout - attrs = make_tcattrs(echo=True) + attrs = _make_tcattrs(echo=True) mock_termios.tcgetattr.return_value = attrs self._run(_) # Ensure those old settings are being restored @@ -1283,7 +1283,7 @@ def tty_stdins_have_settings_restored_on_KeyboardInterrupt( self, mock_tty, mock_termios ): # This test is re: GH issue #303 - sentinel = make_tcattrs(echo=True) + sentinel = _make_tcattrs(echo=True) mock_termios.tcgetattr.return_value = sentinel # Don't actually bubble up the KeyboardInterrupt... try: @@ -1307,7 +1307,7 @@ def setcbreak_not_called_if_terminal_seems_already_cbroken( # Test both bytes and ints versions of CC values, since docs # disagree with at least some platforms' realities on that. for is_ints in (True, False): - mock_termios.tcgetattr.return_value = make_tcattrs( + mock_termios.tcgetattr.return_value = _make_tcattrs( cc_is_ints=is_ints ) self._run(_) @@ -1752,7 +1752,7 @@ def repr_contains_useful_info(self): assert repr(Result(command="foo")) == "" class tail: - def setup(self): + def setup_method(self): self.sample = "\n".join(str(x) for x in range(25)) def returns_last_10_lines_of_given_stream_plus_whitespace(self): diff --git a/tests/task.py b/tests/task.py index 9eafa50ea..b763b162e 100644 --- a/tests/task.py +++ b/tests/task.py @@ -25,7 +25,7 @@ def _load(self, name): mod, _ = self.loader.load(name) return Collection.from_module(mod) - def setup(self): + def setup_method(self): self.loader = Loader(start=support) self.vanilla = self._load("decorators") @@ -215,7 +215,7 @@ def can_override_name(self): assert Task(_func, name="foo").name == "foo" class callability: - def setup(self): + def setup_method(self): @task def foo(c): "My docstring" @@ -258,7 +258,7 @@ def wraps_body_name(self): assert self.task.__name__ == "foo" class get_arguments: - def setup(self): + def setup_method(self): @task(positional=["arg_3", "arg1"], optional=["arg1"]) def mytask(c, arg1, arg2=False, arg_3=5): pass @@ -378,7 +378,7 @@ def mytask(c, longer_arg): assert arg.name == "longer_arg" class help: - def setup(self): + def setup_method(self): @task( help={ "simple": "key", @@ -450,7 +450,7 @@ def second(c, shared): class Call_: - def setup(self): + def setup_method(self): self.task = Task(Mock(__name__="mytask")) class init: