Beispiel #1
0
    def testRun7(self):
        commands = [
            [0, incrementA],
            [-1.23, incrementB],
        ]
        self.assertTrue(revl.validate(commands))

        context = revl.run(commands, 123)
        self.assertIsInstance(context, revl.Context)
Beispiel #2
0
    def testRun2(self):
        commands = [
            (1.0, incrementA),
            (0.0, incrementB),
        ]
        self.assertTrue(revl.validate(commands))

        context = revl.run(commands, 123)
        self.assertIsInstance(context, revl.Context)
        self.assertEqual(globalA, 123)
        self.assertEqual(globalB, 0)
Beispiel #3
0
    def testRun4(self):
        global globalA, globalB
        commands = [
            (2.34, incrementA),
            (1.23, incrementB),
        ]
        self.assertTrue(revl.validate(commands))

        aValues = []
        bValues = []
        for _ in range(123):
            globalA = 0
            globalB = 0
            context = revl.run(commands, 123, seed=1.23)
            self.assertIsInstance(context, revl.Context)
            aValues.append(globalA)
            bValues.append(globalB)

        self.assertTrue(all(a == globalA for a in aValues))
        self.assertTrue(all(b == globalB for b in bValues))
Beispiel #4
0
    def testErrorMessages(self):
        def dummy(context):
            pass

        with self.assertRaises(TypeError) as c:
            revl.validate('abc')

        self.assertEqual(
            str(c.exception),
            "The command set is expected to be an instance object of type 'list', or 'tuple', not 'str'."
        )

        with self.assertRaises(TypeError) as c:
            revl.validate(['abc'])

        self.assertEqual(
            str(c.exception),
            "Each command is expected to be an instance object of type 'list', 'tuple', or 'revl.Command', not 'str'."
        )

        with self.assertRaises(TypeError) as c:
            revl.validate([()])

        self.assertEqual(
            str(c.exception),
            "Each command is expected to be an instance object of type 'list', 'tuple', or 'revl.Command', and compatible with the 'revl.Command' structure, but got '()' instead."
        )

        with self.assertRaises(TypeError) as c:
            revl.validate([('abc', dummy, (), {})])

        self.assertEqual(
            str(c.exception),
            "The first element of a command, that is the 'weight' attribute, is expected to be a real number, not 'str'."
        )

        with self.assertRaises(TypeError) as c:
            revl.validate([(1.0, 'abc', (), {})])

        self.assertEqual(
            str(c.exception),
            "The second element of a command, that is the 'function' attribute, is expected to be a callable object, not 'str'."
        )

        with self.assertRaises(TypeError) as c:
            revl.validate([(1.0, dummy, 'abc', {})])

        self.assertEqual(
            str(c.exception),
            "The third element of a command, that is the 'args' attribute, is expected to be an instance object of type 'list', 'tuple', or 'NoneType', not 'str'."
        )

        with self.assertRaises(TypeError) as c:
            revl.validate([(1.0, dummy, (), 'abc')])

        self.assertEqual(
            str(c.exception),
            "The fourth element of a command, that is the 'kwargs' attribute, is expected to be an instance object of type 'dict', or 'NoneType', not 'str'."
        )
Beispiel #5
0
    def testRun6(self):
        commands = []
        self.assertTrue(revl.validate(commands))

        context = revl.run(commands, 123, context=revl.Context())
        self.assertIsInstance(context, revl.Context)