Skip to content

Commit e520f14

Browse files
committed
Revise naming + add a usage description.
1 parent 90d4465 commit e520f14

File tree

9 files changed

+83
-75
lines changed

9 files changed

+83
-75
lines changed

lib/iris/tests/__init__.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def get_data_path(relative_path):
220220
return data_path
221221

222222

223-
class _IrisTest_nometa(unittest.TestCase):
223+
class IrisTest_nometa(unittest.TestCase):
224224
"""A subclass of unittest.TestCase which provides Iris specific testing functionality."""
225225

226226
_assertion_counts = collections.defaultdict(int)
@@ -855,6 +855,15 @@ def assertArrayShapeStats(self, result, shape, mean, std_dev, rtol=1e-6):
855855

856856

857857
# An environment variable controls whether test timings are output.
858+
#
859+
# NOTE: to run tests with timing output, nosetests cannot be used.
860+
# At present, that includes not using "python setup.py test"
861+
# The typically best way is like this :
862+
# $ export IRIS_TEST_TIMINGS=1
863+
# $ python -m unittest discover -s iris.tests
864+
# and commonly adding ...
865+
# | grep "TIMING TEST" >iris_test_output.txt
866+
#
858867
_PRINT_TEST_TIMINGS = bool(int(os.environ.get('IRIS_TEST_TIMINGS', 0)))
859868

860869

@@ -863,7 +872,7 @@ def _method_path(meth):
863872
return '.'.join([cls.__module__, cls.__name__, meth.__name__])
864873

865874

866-
def _test_timings_function_decorator(fn):
875+
def _testfunction_timing_decorator(fn):
867876
# Function decorator for making a testcase print its execution time.
868877
@functools.wraps(fn)
869878
def inner(*args, **kwargs):
@@ -880,44 +889,43 @@ def inner(*args, **kwargs):
880889
return inner
881890

882891

883-
def _test_timings_class_decorator(cls):
892+
def iristest_timing_decorator(cls):
884893
# Class decorator to make all "test_.." functions print execution timings.
885894
if _PRINT_TEST_TIMINGS:
886-
# NOTE: 'dir' hits *all* function properties, including inherited ones.
895+
# NOTE: 'dir' scans *all* class properties, including inherited ones.
887896
attr_names = dir(cls)
888897
for attr_name in attr_names:
889898
attr = getattr(cls, attr_name)
890899
if callable(attr) and attr_name.startswith('test'):
891-
attr = _test_timings_function_decorator(attr)
900+
attr = _testfunction_timing_decorator(attr)
892901
setattr(cls, attr_name, attr)
893902
return cls
894903

895904

896-
class TestTimingsMetaclass(type):
905+
class _TestTimingsMetaclass(type):
897906
# An alternative metaclass for IrisTest subclasses, which makes
898907
# them print execution timings for all the testcases.
899-
# This is equivalent to applying the @_test_timings_class_decorator to
908+
# This is equivalent to applying the @iristest_timing_decorator to
900909
# every test class that inherits from IrisTest.
901910
# NOTE: however, it means you *cannot* specify a different metaclass for
902911
# your test class inheriting from IrisTest.
903912
# See below for how to solve that where needed.
904913
def __new__(cls, clsname, base_classes, attrs):
905914
result = type.__new__(cls, clsname, base_classes, attrs)
906915
if _PRINT_TEST_TIMINGS:
907-
result = _test_timings_class_decorator(result)
916+
result = iristest_timing_decorator(result)
908917
return result
909918

910919

911-
class IrisTest(_IrisTest_nometa):
912-
# Derive the 'ordinary' IrisTest from _IrisTest_nometa, but add the
920+
class IrisTest(six.with_metaclass(_TestTimingsMetaclass, IrisTest_nometa)):
921+
# Derive the 'ordinary' IrisTest from IrisTest_nometa, but add the
913922
# metaclass that enables test timings output.
914923
# This means that all subclasses also get the timing behaviour.
915924
# However, if a different metaclass is *wanted* for an IrisTest subclass,
916925
# this would cause a metaclass conflict.
917-
# Instead, you can inherit from _IrisTest_nometa and apply the
918-
# @_test_timings_class_decorator explicitly to your new testclass.
919-
if _PRINT_TEST_TIMINGS:
920-
__metaclass__ = TestTimingsMetaclass
926+
# Instead, you can inherit from IrisTest_nometa and apply the
927+
# @iristest_timing_decorator explicitly to your new testclass.
928+
pass
921929

922930

923931
get_result_path = IrisTest.get_result_path
@@ -950,7 +958,7 @@ class GraphicsTest(GraphicsTestMixin, IrisTest):
950958
pass
951959

952960

953-
class GraphicsTest_nometa(GraphicsTestMixin, _IrisTest_nometa):
961+
class GraphicsTest_nometa(GraphicsTestMixin, IrisTest_nometa):
954962
# Graphicstest without the metaclass providing test timings.
955963
pass
956964

lib/iris/tests/test_plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def override_with_decorated_methods(attr_dict, target_dict,
581581

582582

583583
@tests.skip_data
584-
@tests._test_timings_class_decorator
584+
@tests.iristest_timing_decorator
585585
class TestPcolorNoBounds(six.with_metaclass(CheckForWarningsMetaclass,
586586
tests.GraphicsTest_nometa,
587587
SliceMixin)):
@@ -597,7 +597,7 @@ def setUp(self):
597597

598598

599599
@tests.skip_data
600-
@tests._test_timings_class_decorator
600+
@tests.iristest_timing_decorator
601601
class TestPcolormeshNoBounds(six.with_metaclass(CheckForWarningsMetaclass,
602602
tests.GraphicsTest_nometa,
603603
SliceMixin)):

lib/iris/tests/unit/analysis/maths/test_add.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232

3333
@tests.skip_data
34-
@tests._test_timings_class_decorator
35-
class TestBroadcasting(tests._IrisTest_nometa,
34+
@tests.iristest_timing_decorator
35+
class TestBroadcasting(tests.IrisTest_nometa,
3636
CubeArithmeticBroadcastingTestMixin):
3737
@property
3838
def data_op(self):
@@ -43,8 +43,8 @@ def cube_func(self):
4343
return add
4444

4545

46-
@tests._test_timings_class_decorator
47-
class TestMasking(tests._IrisTest_nometa, CubeArithmeticMaskingTestMixin):
46+
@tests.iristest_timing_decorator
47+
class TestMasking(tests.IrisTest_nometa, CubeArithmeticMaskingTestMixin):
4848
@property
4949
def data_op(self):
5050
return operator.add

lib/iris/tests/unit/analysis/maths/test_divide.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333

3434

3535
@tests.skip_data
36-
@tests._test_timings_class_decorator
37-
class TestBroadcasting(tests._IrisTest_nometa,
36+
@tests.iristest_timing_decorator
37+
class TestBroadcasting(tests.IrisTest_nometa,
3838
CubeArithmeticBroadcastingTestMixin):
3939
@property
4040
def data_op(self):
@@ -48,8 +48,8 @@ def cube_func(self):
4848
return divide
4949

5050

51-
@tests._test_timings_class_decorator
52-
class TestMasking(tests._IrisTest_nometa, CubeArithmeticMaskingTestMixin):
51+
@tests.iristest_timing_decorator
52+
class TestMasking(tests.IrisTest_nometa, CubeArithmeticMaskingTestMixin):
5353
@property
5454
def data_op(self):
5555
try:

lib/iris/tests/unit/analysis/maths/test_multiply.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232

3333
@tests.skip_data
34-
@tests._test_timings_class_decorator
35-
class TestBroadcasting(tests._IrisTest_nometa,
34+
@tests.iristest_timing_decorator
35+
class TestBroadcasting(tests.IrisTest_nometa,
3636
CubeArithmeticBroadcastingTestMixin):
3737
@property
3838
def data_op(self):
@@ -43,8 +43,8 @@ def cube_func(self):
4343
return multiply
4444

4545

46-
@tests._test_timings_class_decorator
47-
class TestMasking(tests._IrisTest_nometa, CubeArithmeticMaskingTestMixin):
46+
@tests.iristest_timing_decorator
47+
class TestMasking(tests.IrisTest_nometa, CubeArithmeticMaskingTestMixin):
4848
@property
4949
def data_op(self):
5050
return operator.mul

lib/iris/tests/unit/analysis/maths/test_subtract.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232

3333
@tests.skip_data
34-
@tests._test_timings_class_decorator
35-
class TestBroadcasting(tests._IrisTest_nometa,
34+
@tests.iristest_timing_decorator
35+
class TestBroadcasting(tests.IrisTest_nometa,
3636
CubeArithmeticBroadcastingTestMixin):
3737
@property
3838
def data_op(self):
@@ -43,8 +43,8 @@ def cube_func(self):
4343
return subtract
4444

4545

46-
@tests._test_timings_class_decorator
47-
class TestMasking(tests._IrisTest_nometa, CubeArithmeticMaskingTestMixin):
46+
@tests.iristest_timing_decorator
47+
class TestMasking(tests.IrisTest_nometa, CubeArithmeticMaskingTestMixin):
4848
@property
4949
def data_op(self):
5050
return operator.sub

lib/iris/tests/unit/fileformats/grib/message/test_GribMessage.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,36 +211,36 @@ def _example_section_3(grib_definition_template_number, scanning_mode):
211211
'Ni': 4}
212212

213213

214-
@tests._test_timings_class_decorator
215-
class Test_data__grid_template_0(tests._IrisTest_nometa,
214+
@tests.iristest_timing_decorator
215+
class Test_data__grid_template_0(tests.IrisTest_nometa,
216216
Mixin_data__grid_template):
217217
def section_3(self, scanning_mode):
218218
return _example_section_3(0, scanning_mode)
219219

220220

221-
@tests._test_timings_class_decorator
222-
class Test_data__grid_template_1(tests._IrisTest_nometa,
221+
@tests.iristest_timing_decorator
222+
class Test_data__grid_template_1(tests.IrisTest_nometa,
223223
Mixin_data__grid_template):
224224
def section_3(self, scanning_mode):
225225
return _example_section_3(1, scanning_mode)
226226

227227

228-
@tests._test_timings_class_decorator
229-
class Test_data__grid_template_5(tests._IrisTest_nometa,
228+
@tests.iristest_timing_decorator
229+
class Test_data__grid_template_5(tests.IrisTest_nometa,
230230
Mixin_data__grid_template):
231231
def section_3(self, scanning_mode):
232232
return _example_section_3(5, scanning_mode)
233233

234234

235-
@tests._test_timings_class_decorator
236-
class Test_data__grid_template_12(tests._IrisTest_nometa,
235+
@tests.iristest_timing_decorator
236+
class Test_data__grid_template_12(tests.IrisTest_nometa,
237237
Mixin_data__grid_template):
238238
def section_3(self, scanning_mode):
239239
return _example_section_3(12, scanning_mode)
240240

241241

242-
@tests._test_timings_class_decorator
243-
class Test_data__grid_template_30(tests._IrisTest_nometa,
242+
@tests.iristest_timing_decorator
243+
class Test_data__grid_template_30(tests.IrisTest_nometa,
244244
Mixin_data__grid_template):
245245
def section_3(self, scanning_mode):
246246
section_3 = _example_section_3(30, scanning_mode)
@@ -252,15 +252,15 @@ def section_3(self, scanning_mode):
252252
return section_3
253253

254254

255-
@tests._test_timings_class_decorator
256-
class Test_data__grid_template_40_regular(tests._IrisTest_nometa,
255+
@tests.iristest_timing_decorator
256+
class Test_data__grid_template_40_regular(tests.IrisTest_nometa,
257257
Mixin_data__grid_template):
258258
def section_3(self, scanning_mode):
259259
return _example_section_3(40, scanning_mode)
260260

261261

262-
@tests._test_timings_class_decorator
263-
class Test_data__grid_template_90(tests._IrisTest_nometa,
262+
@tests.iristest_timing_decorator
263+
class Test_data__grid_template_90(tests.IrisTest_nometa,
264264
Mixin_data__grid_template):
265265
def section_3(self, scanning_mode):
266266
section_3 = _example_section_3(90, scanning_mode)

0 commit comments

Comments
 (0)