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

Make unit/config pytest #5810

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 26 additions & 27 deletions lib/iris/tests/unit/config/test_NetCDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,40 @@
# See LICENSE in the root of the repository for full licensing details.
"""Unit tests for the `iris.config.NetCDF` class."""

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

import re
import warnings

import pytest

import iris.config


class Test(tests.IrisTest):
def setUp(self):
self.options = iris.config.NetCDF()
@pytest.fixture
def options():
return iris.config.NetCDF()


def test_basic(options):
assert not options.conventions_override

def test_basic(self):
self.assertFalse(self.options.conventions_override)

def test_enabled(self):
self.options.conventions_override = True
self.assertTrue(self.options.conventions_override)
def test_enabled(options):
options.conventions_override = True
assert options.conventions_override

def test_bad_value(self):
# A bad value should be ignored and replaced with the default value.
bad_value = "wibble"
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
self.options.conventions_override = bad_value
self.assertFalse(self.options.conventions_override)
exp_wmsg = "Attempting to set invalid value {!r}".format(bad_value)
self.assertRegex(str(w[0].message), exp_wmsg)

def test__contextmgr(self):
with self.options.context(conventions_override=True):
self.assertTrue(self.options.conventions_override)
self.assertFalse(self.options.conventions_override)
def test_bad_value(options):
# A bad value should be ignored and replaced with the default value.
bad_value = "wibble"
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
options.conventions_override = bad_value
assert not options.conventions_override
exp_wmsg = "Attempting to set invalid value {!r}".format(bad_value)
assert re.match(exp_wmsg, str(w[0].message))


if __name__ == "__main__":
tests.main()
def test__contextmgr(options):
with options.context(conventions_override=True):
assert options.conventions_override
assert not options.conventions_override