Esempio n. 1
0
    def test_create(self):
        with self.assertRaises(IOError):
            s = Surface("File/does/not/exist")

        with self.assertRaises(ValueError):
            s = Surface(self.surface_short)

        with self.assertRaises(ValueError):
            s = Surface(self.surface_long)

        s = Surface(self.surface_valid)

        self.assertEqual(s.getNX(), 49)
        self.assertEqual(s.getNY(), 79)
        self.assertEqual(len(s), 49 * 79)

        with self.assertRaises(IndexError):
            v = s[49 * 79]

        with self.assertRaises(TypeError):
            v = s["KEY"]

        self.assertEqual(s[0], 0.0051)
        self.assertEqual(s[-1], -0.0014)

        with self.assertRaises(IndexError):
            s[49 * 79] = 787

        s[0] = 10
        self.assertEqual(s[0], 10)

        s[-1] = 77
        self.assertEqual(s[len(s) - 1], 77)
Esempio n. 2
0
    def test_create_new(self):
        with self.assertRaises(ValueError):
            s = Surface(None, 1, 1, 1)
        with self.assertRaises(IOError):
            s = Surface(50, 1, 1, 1)

        # values copied from irap surface_small
        ny, nx = 20, 30
        xinc, yinc = 50.0, 50.0
        xstart, ystart = 463325.5625, 7336963.5
        angle = -65.0
        s_args = (None, nx, ny, xinc, yinc, xstart, ystart, angle)
        s = Surface(*s_args)
        self.assertEqual(ny * nx, len(s))
        self.assertEqual(nx, s.getNX())
        self.assertEqual(ny, s.getNY())
        small = Surface(self.surface_small)
        self.assertTrue(small.headerEqual(s))
        valid = Surface(self.surface_valid)
        self.assertFalse(valid.headerEqual(s))

        self.assertNotEqual(s, small)
        idx = 0
        for i in range(nx):
            for j in range(ny):
                s[idx] = small[idx]
                idx += 1
        self.assertEqual(s, small)