Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest migration for unit.common.lenient.test__qualname #5845

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions lib/iris/tests/unit/common/lenient/test__qualname.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,37 @@
# See LICENSE in the root of the repository for full licensing details.
"""Unit tests for the :func:`iris.common.lenient._qualname`."""

# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip

from inspect import getmodule
from unittest.mock import sentinel

import pytest

from iris.common.lenient import _qualname


class Test(tests.IrisTest):
def setUp(self):
class Test:
@pytest.fixture(autouse=True)
def _setup(self):
module_name = getmodule(self).__name__
self.locals = f"{module_name}" + ".Test.{}.<locals>.{}"

def test_pass_thru_non_callable(self):
func = sentinel.func
def test_pass_thru_non_callable(self, mocker):
func = mocker.sentinel.func
result = _qualname(func)
self.assertEqual(result, func)
assert result == func

def test_callable_function_local(self):
def myfunc():
pass

qualname_func = self.locals.format("test_callable_function_local", "myfunc")
result = _qualname(myfunc)
self.assertEqual(result, qualname_func)
assert result == qualname_func

def test_callable_function(self):
import iris

result = _qualname(iris.load)
self.assertEqual(result, "iris.load")
assert result == "iris.load"

def test_callable_method_local(self):
class MyClass:
Expand All @@ -47,14 +45,10 @@ def mymethod(self):
"test_callable_method_local", "MyClass.mymethod"
)
result = _qualname(MyClass.mymethod)
self.assertEqual(result, qualname_method)
assert result == qualname_method

def test_callable_method(self):
import iris

result = _qualname(iris.cube.Cube.add_ancillary_variable)
self.assertEqual(result, "iris.cube.Cube.add_ancillary_variable")


if __name__ == "__main__":
tests.main()
assert result == "iris.cube.Cube.add_ancillary_variable"
Loading