Пример #1
0
 def test_derived_points(self):
     # Broadcast expected points given the known dimensional mapping.
     s = self.s.points[..., np.newaxis, np.newaxis]
     eta = self.eta.points[np.newaxis, ...]
     depth = self.depth.points[np.newaxis, ...]
     a = self.a.points
     b = self.b.points
     depth_c = self.depth_c.points
     # Calculate the expected result.
     expected_coord = self.derive(s, eta, depth, a, b, depth_c)
     # Calculate the actual result.
     factory = OceanSFactory(**self.kwargs)
     coord = factory.make_coord(self.coord_dims)
     self.assertEqual(expected_coord, coord)
Пример #2
0
 def setUp(self):
     self.s = mock.Mock(units=Unit('1'), nbounds=0)
     self.eta = mock.Mock(units=Unit('m'), nbounds=0)
     self.depth = mock.Mock(units=Unit('m'), nbounds=0)
     self.a = mock.Mock(units=Unit('1'), nbounds=0, shape=(1,))
     self.b = mock.Mock(units=Unit('1'), nbounds=0, shape=(1,))
     self.depth_c = mock.Mock(units=Unit('m'), nbounds=0, shape=(1,))
     self.kwargs = dict(s=self.s, eta=self.eta, depth=self.depth,
                        a=self.a, b=self.b, depth_c=self.depth_c)
     self.factory = OceanSFactory(**self.kwargs)
Пример #3
0
class Test_update(tests.IrisTest):
    def setUp(self):
        self.s = mock.Mock(units=Unit('1'), nbounds=0)
        self.eta = mock.Mock(units=Unit('m'), nbounds=0)
        self.depth = mock.Mock(units=Unit('m'), nbounds=0)
        self.a = mock.Mock(units=Unit('1'), nbounds=0, shape=(1,))
        self.b = mock.Mock(units=Unit('1'), nbounds=0, shape=(1,))
        self.depth_c = mock.Mock(units=Unit('m'), nbounds=0, shape=(1,))
        self.kwargs = dict(s=self.s, eta=self.eta, depth=self.depth,
                           a=self.a, b=self.b, depth_c=self.depth_c)
        self.factory = OceanSFactory(**self.kwargs)

    def test_s(self):
        new_s = mock.Mock(units=Unit('1'), nbounds=0)
        self.factory.update(self.s, new_s)
        self.assertIs(self.factory.s, new_s)

    def test_s_too_many_bounds(self):
        new_s = mock.Mock(units=Unit('1'), nbounds=4)
        with self.assertRaises(ValueError):
            self.factory.update(self.s, new_s)

    def test_s_incompatible_units(self):
        new_s = mock.Mock(units=Unit('Pa'), nbounds=0)
        with self.assertRaises(ValueError):
            self.factory.update(self.s, new_s)

    def test_eta(self):
        new_eta = mock.Mock(units=Unit('m'), nbounds=0)
        self.factory.update(self.eta, new_eta)
        self.assertIs(self.factory.eta, new_eta)

    def test_eta_incompatible_units(self):
        new_eta = mock.Mock(units=Unit('Pa'), nbounds=0)
        with self.assertRaises(ValueError):
            self.factory.update(self.eta, new_eta)

    def test_depth(self):
        new_depth = mock.Mock(units=Unit('m'), nbounds=0)
        self.factory.update(self.depth, new_depth)
        self.assertIs(self.factory.depth, new_depth)

    def test_depth_incompatible_units(self):
        new_depth = mock.Mock(units=Unit('Pa'), nbounds=0)
        with self.assertRaises(ValueError):
            self.factory.update(self.depth, new_depth)

    def test_a(self):
        new_a = mock.Mock(units=Unit('1'), nbounds=0, shape=(1,))
        self.factory.update(self.a, new_a)
        self.assertIs(self.factory.a, new_a)

    def test_a_non_scalar(self):
        new_a = mock.Mock(units=Unit('1'), nbounds=0, shape=(10,))
        with self.assertRaises(ValueError):
            self.factory.update(self.a, new_a)

    def test_b(self):
        new_b = mock.Mock(units=Unit('1'), nbounds=0, shape=(1,))
        self.factory.update(self.b, new_b)
        self.assertIs(self.factory.b, new_b)

    def test_b_non_scalar(self):
        new_b = mock.Mock(units=Unit('1'), nbounds=0, shape=(10,))
        with self.assertRaises(ValueError):
            self.factory.update(self.b, new_b)

    def test_depth_c(self):
        new_depth_c = mock.Mock(units=Unit('m'), nbounds=0, shape=(1,))
        self.factory.update(self.depth_c, new_depth_c)
        self.assertIs(self.factory.depth_c, new_depth_c)

    def test_depth_c_non_scalar(self):
        new_depth_c = mock.Mock(units=Unit('m'), nbounds=0, shape=(10,))
        with self.assertRaises(ValueError):
            self.factory.update(self.depth_c, new_depth_c)

    def test_depth_c_incompatible_units(self):
        new_depth_c = mock.Mock(units=Unit('Pa'), nbounds=0, shape=(1,))
        with self.assertRaises(ValueError):
            self.factory.update(self.depth_c, new_depth_c)
Пример #4
0
 def test_depth_c_non_scalar(self):
     self.depth_c.shape = (2,)
     with self.assertRaises(ValueError):
         OceanSFactory(**self.kwargs)
Пример #5
0
 def test_depth_incompatible_units(self):
     self.depth.units = Unit("km")
     with self.assertRaises(ValueError):
         OceanSFactory(**self.kwargs)
Пример #6
0
 def test_s_too_many_bounds(self):
     self.s.nbounds = 4
     with self.assertRaises(ValueError):
         OceanSFactory(**self.kwargs)
Пример #7
0
class Test_update(tests.IrisTest):
    def setUp(self):
        self.s = mock.Mock(units=Unit("1"), nbounds=0)
        self.eta = mock.Mock(units=Unit("m"), nbounds=0)
        self.depth = mock.Mock(units=Unit("m"), nbounds=0)
        self.a = mock.Mock(units=Unit("1"), nbounds=0, shape=(1,))
        self.b = mock.Mock(units=Unit("1"), nbounds=0, shape=(1,))
        self.depth_c = mock.Mock(units=Unit("m"), nbounds=0, shape=(1,))
        self.kwargs = dict(
            s=self.s,
            eta=self.eta,
            depth=self.depth,
            a=self.a,
            b=self.b,
            depth_c=self.depth_c,
        )
        self.factory = OceanSFactory(**self.kwargs)

    def test_s(self):
        new_s = mock.Mock(units=Unit("1"), nbounds=0)
        self.factory.update(self.s, new_s)
        self.assertIs(self.factory.s, new_s)

    def test_s_too_many_bounds(self):
        new_s = mock.Mock(units=Unit("1"), nbounds=4)
        with self.assertRaises(ValueError):
            self.factory.update(self.s, new_s)

    def test_s_incompatible_units(self):
        new_s = mock.Mock(units=Unit("Pa"), nbounds=0)
        with self.assertRaises(ValueError):
            self.factory.update(self.s, new_s)

    def test_eta(self):
        new_eta = mock.Mock(units=Unit("m"), nbounds=0)
        self.factory.update(self.eta, new_eta)
        self.assertIs(self.factory.eta, new_eta)

    def test_eta_incompatible_units(self):
        new_eta = mock.Mock(units=Unit("Pa"), nbounds=0)
        with self.assertRaises(ValueError):
            self.factory.update(self.eta, new_eta)

    def test_depth(self):
        new_depth = mock.Mock(units=Unit("m"), nbounds=0)
        self.factory.update(self.depth, new_depth)
        self.assertIs(self.factory.depth, new_depth)

    def test_depth_incompatible_units(self):
        new_depth = mock.Mock(units=Unit("Pa"), nbounds=0)
        with self.assertRaises(ValueError):
            self.factory.update(self.depth, new_depth)

    def test_a(self):
        new_a = mock.Mock(units=Unit("1"), nbounds=0, shape=(1,))
        self.factory.update(self.a, new_a)
        self.assertIs(self.factory.a, new_a)

    def test_a_non_scalar(self):
        new_a = mock.Mock(units=Unit("1"), nbounds=0, shape=(10,))
        with self.assertRaises(ValueError):
            self.factory.update(self.a, new_a)

    def test_b(self):
        new_b = mock.Mock(units=Unit("1"), nbounds=0, shape=(1,))
        self.factory.update(self.b, new_b)
        self.assertIs(self.factory.b, new_b)

    def test_b_non_scalar(self):
        new_b = mock.Mock(units=Unit("1"), nbounds=0, shape=(10,))
        with self.assertRaises(ValueError):
            self.factory.update(self.b, new_b)

    def test_depth_c(self):
        new_depth_c = mock.Mock(units=Unit("m"), nbounds=0, shape=(1,))
        self.factory.update(self.depth_c, new_depth_c)
        self.assertIs(self.factory.depth_c, new_depth_c)

    def test_depth_c_non_scalar(self):
        new_depth_c = mock.Mock(units=Unit("m"), nbounds=0, shape=(10,))
        with self.assertRaises(ValueError):
            self.factory.update(self.depth_c, new_depth_c)

    def test_depth_c_incompatible_units(self):
        new_depth_c = mock.Mock(units=Unit("Pa"), nbounds=0, shape=(1,))
        with self.assertRaises(ValueError):
            self.factory.update(self.depth_c, new_depth_c)
Пример #8
0
 def test_values(self):
     factory = OceanSFactory(**self.kwargs)
     self.assertEqual(factory.dependencies, self.kwargs)
Пример #9
0
 def test_promote_s_units_unknown_to_dimensionless(self):
     s = mock.Mock(units=Unit("unknown"), nbounds=0)
     self.kwargs["s"] = s
     factory = OceanSFactory(**self.kwargs)
     self.assertEqual("1", factory.dependencies["s"].units)
Пример #10
0
 def test_eta_incompatible_units(self):
     self.eta.units = Unit('km')
     with self.assertRaises(ValueError):
         OceanSFactory(**self.kwargs)