Exemplo n.º 1
0
Arquivo: tests.py Projeto: xfcl/libzmx
    def runTest(self) :
        z = Connection()

        response = z.NewLens()
        self.assertFalse(response, "Can't create new lens")

        # find number of surfaces
        response = z.GetSystem()
        numsurfs1 = response[0]

        response = z.InsertSurface(2)
        self.assertFalse(response, "Can't insert a surface")

        # check number of surfaces increased
        response = z.GetSystem()
        numsurfs2 = response[0]
        self.assertEqual(numsurfs2, numsurfs1+1, "Number of surfaces didn't increase")

        # copy lens to editor
        response = z.PushLens()
        self.assertFalse(response, "Can't push lens to editor window")

        response = z.NewLens()
        self.assertFalse(response, "Can't create new lens")
        
        response = z.GetSystem()
        self.assertNotEqual(response[0], numsurfs2,
                            "New lens has same number of surfaces as old (modified) one")

        # copy modified lens back into server memory        
        response = z.GetRefresh()

        # check it's our modified lens
        response = z.GetSystem()
        self.assertEqual(response[0], numsurfs2, "Didn't get our lens back")
Exemplo n.º 2
0
class ClientDeleteSurface(unittest.TestCase):
    """Check that we understand the semantics of the DeleteSurface method.

    Delete 0 => No effect
    Delete 1 => Delete surface 1 (first surface after object)
    Delete n-1 => Delete last surface (penultimate surface becomes image)
    Delete i (where i>=n) => As Delete n-1
    """
    def setUp(self):
        self.z = Connection()
        self.z.NewLens()

        self.z.InsertSurface(1)
        self.z.InsertSurface(1)

        self.n = self.get_len()
        for i in range(self.n):
            self.z.SetLabel(i, i)

    def get_len(self):
        response = self.z.GetSystem()
        return response[0]+1

    def ListLabels(self):
        for i in range(self.get_len()):
            print((i, self.z.GetLabel(i)))

    def testFind(self):
        for i in range(self.n):
            j = self.z.FindLabel(i)
            self.assertEqual(i, j)

    def testDeleteAtZero(self):
        z = self.z
        n = self.n

        # Delete at zero does nothing
        z.DeleteSurface(0)

        self.assertEqual(n, self.get_len())

    def testDeleteAtOne(self):
        z = self.z
        n = self.n

        # Delete at 1 deletes after object surface
        z.DeleteSurface(1)

        self.assertEqual(n-1, self.get_len())
        # i=1 removed
        self.assertRaises(SurfaceLabelError, lambda: z.FindLabel(1))

    def testDeleteAtEnd(self):
        z = self.z
        n = self.n

        # Delete at n-1 removes image surface
        z.DeleteSurface(n-1)

        self.assertEqual(n-1, self.get_len())
        # i=n-1 removed
        self.assertRaises(SurfaceLabelError, lambda: z.FindLabel(n-1))

    def testDeleteAt100(self):
        z = self.z
        n = self.n

        # Delete at i>>n removes image surface
        z.DeleteSurface(100)

        self.assertEqual(n-1, self.get_len())
        # i=n-1 removed
        self.assertRaises(SurfaceLabelError, lambda: z.FindLabel(n-1))