コード例 #1
0
class Test_rename(tests.IrisTest):
    def setUp(self):
        metadata = mock.MagicMock(
            standard_name=mock.sentinel.standard_name,
            long_name=mock.sentinel.long_name,
            var_name=mock.sentinel.var_name,
            units=mock.sentinel.units,
            attributes=mock.sentinel.attributes,
            values=mock.sentinel.metadata,
            token=lambda name: name,
        )

        self.item = CFVariableMixin()
        self.item._metadata_manager = metadata

    def test__valid_standard_name(self):
        name = "air_temperature"
        self.item.rename(name)
        self.assertEqual(self.item._metadata_manager.standard_name, name)
        self.assertIsNone(self.item._metadata_manager.long_name)
        self.assertIsNone(self.item._metadata_manager.var_name)

    def test__invalid_standard_name(self):
        name = "nope nope"
        self.item.rename(name)
        self.assertIsNone(self.item._metadata_manager.standard_name)
        self.assertEqual(self.item._metadata_manager.long_name, name)
        self.assertIsNone(self.item._metadata_manager.var_name)
コード例 #2
0
    def setUp(self):
        class Metadata:
            def __init__(self, name):
                self.name = mock.MagicMock(return_value=name)

        self.name = mock.sentinel.name
        metadata = Metadata(self.name)

        self.item = CFVariableMixin()
        self.item._metadata_manager = metadata
コード例 #3
0
    def setUp(self):
        metadata = mock.MagicMock(
            standard_name=mock.sentinel.standard_name,
            long_name=mock.sentinel.long_name,
            var_name=mock.sentinel.var_name,
            units=mock.sentinel.units,
            attributes=mock.sentinel.attributes,
            values=mock.sentinel.metadata,
            token=lambda name: name,
        )

        self.item = CFVariableMixin()
        self.item._metadata_manager = metadata
コード例 #4
0
    def setUp(self):
        class Metadata:
            def __init__(self):
                self.cls = BaseMetadata
                self.fields = BaseMetadata._fields
                self.standard_name = mock.sentinel.standard_name
                self.long_name = mock.sentinel.long_name
                self.var_name = mock.sentinel.var_name
                self.units = mock.sentinel.units
                self.attributes = mock.sentinel.attributes
                self.token = lambda name: name

            @property
            def values(self):
                return dict(
                    standard_name=self.standard_name,
                    long_name=self.long_name,
                    var_name=self.var_name,
                    units=self.units,
                    attributes=self.attributes,
                )

        metadata = Metadata()
        self.item = CFVariableMixin()
        self.item._metadata_manager = metadata
        self.attributes = dict(one=1, two=2, three=3)
        self.args = OrderedDict(
            standard_name="air_temperature",
            long_name="long_name",
            var_name="var_name",
            units=Unit("1"),
            attributes=self.attributes,
        )
コード例 #5
0
class Test_name(tests.IrisTest):
    def setUp(self):
        class Metadata:
            def __init__(self, name):
                self.name = mock.MagicMock(return_value=name)

        self.name = mock.sentinel.name
        metadata = Metadata(self.name)

        self.item = CFVariableMixin()
        self.item._metadata_manager = metadata

    def test(self):
        default = mock.sentinel.default
        token = mock.sentinel.token
        result = self.item.name(default=default, token=token)
        self.assertEqual(result, self.name)
        self.item._metadata_manager.name.assert_called_with(default=default,
                                                            token=token)