Example #1
0
 def test_randact_many(self):
     """Verify randomized actions with various instances"""
     Randomizer.randact([self.employee, self.rand_entity_1],
                        num_iter=20,
                        nap=lambda: None)
     recorder_history = REC.get_action_details()
     self.assertEqual(20, len(recorder_history))
Example #2
0
    def test_arg_from_object(self):
        """Test that you can access object when randomizing function argument"""
        test_entity_2 = RandomizedEntity2()
        Randomizer.randact(test_entity_2)
        self.assertEqual(1, test_entity_2.status)
        test_entity_2.status = 0

        Randomizer.randact(test_entity_2, num_iter=5, nap=lambda: None)
        self.assertEqual(1, test_entity_2.status)
Example #3
0
 def test_recorder(self):
     """Test action randomizer"""
     self.assertEqual(0, len(REC.get_action_details()))
     Randomizer.randact(self.employee)
     self.assertEqual(1, len(REC.get_action_details()))
     Randomizer.randact([self.employee, self.rand_entity_1],
                        num_iter=9,
                        nap=lambda: None)
     self.assertEqual(10, len(REC.get_action_details()))
Example #4
0
 def test_child_class(self):
     """Verify that inherited methods get randomized as well"""
     Randomizer.randact(self.rand_child_entity_1)
     self.assertEqual(1, len(REC.get_action_details()))
     self.assertTrue(REC.get_action_details()[0]["work"].startswith(
         "RandomizedEntityChild(0).test_method"))
Example #5
0
    def test_randact_many_invalid(self):
        """Verify illegal class instance raising exception"""
        unreg_obj = Dummy()

        with self.assertRaises(ValueError):
            Randomizer.randact([self.employee, self.rand_entity_1, unreg_obj])
Example #6
0
 def test_randact_timed(self):
     """Verify time based action execution"""
     Randomizer.randact(self.employee, seconds=4, nap=lambda: time.sleep(1))
     self.assertGreater(Employee.num_promotions, 1)
Example #7
0
 def test_randact_iter(self):
     """Test randomizer performing specified number of actions"""
     Randomizer.randact(self.employee, num_iter=20, nap=lambda: None)
     self.assertEqual(20, Employee.num_promotions)
Example #8
0
 def test_randact(self):
     """Verify randact performing one random action"""
     Randomizer.randact(self.employee, num_iter=1)
     self.assertEqual(1, Employee.num_promotions)
     self.assertIn(self.employee.title,
                   ["manager", "ceo", "cto", "janitor"])
Example #9
0
    def test_unregistered_class(self):
        """Test invalid instance"""
        unreg_obj = Dummy()

        with self.assertRaises(ValueError):
            Randomizer.randact(unreg_obj)