hope

Finished
1
2import sys, pytest, collections, collections.abc, urllib3.exceptions, _pytest.pytester, numpy;
3collections.Mapping = collections.abc.Mapping;
4collections.MutableMapping = collections.abc.MutableMapping;
5collections.MutableSet = collections.abc.MutableSet;
6collections.Sequence = collections.abc.Sequence;
7collections.Callable = collections.abc.Callable;
8collections.Iterable = collections.abc.Iterable;
9collections.Iterator = collections.abc.Iterator;
10urllib3.exceptions.SNIMissingWarning = urllib3.exceptions.DependencyWarning;
11pytest.RemovedInPytest4Warning = DeprecationWarning;
12_pytest.pytester.Testdir = _pytest.pytester.Pytester;
13numpy.PINF = numpy.inf;
14numpy.unicode_ = numpy.str_;
15numpy.bytes_ = numpy.bytes_;
16numpy.float_ = numpy.float64;
17numpy.string_ = numpy.bytes_;
18numpy.NaN = numpy.nan;
19
20
21import unittest
22from main import Robot
23
24class ExhaustionTest(unittest.TestCase):
25 def test_name_pool_exhaustion_error(self):
26 """Test that proper error is raised when name pool is exhausted"""
27 # This test simulates exhaustion by using all names
28 # Save original pool
29 original_pool = Robot._available_names.copy()
30
31 try:
32 # Create a small pool for testing
33 Robot._available_names.clear()
34 Robot._available_names.extend(["AA111", "BB222", "CC333"])
35
36 # Use all names
37 robots = []
38 for i in range(3):
39 robot = Robot()
40 _ = robot.name # Generate the name
41 robots.append(robot)
42
43 # Now try to create another robot - should fail
44 # But first prevent regeneration by patching the method
45 def no_regeneration(self):
46 pass
47
48 # Save original method
49 original_generate = Robot._generate_name_pool
50 Robot._generate_name_pool = no_regeneration
51
52 try:
53 robot4 = Robot()
54 with self.assertRaises(RuntimeError) as context:
55 _ = robot4.name
56
57 self.assertIn("No more unique names available", str(context.exception))
58 finally:
59 # Restore original method
60 Robot._generate_name_pool = original_generate
61
62 finally:
63 # Restore the pool
64 Robot._available_names.clear()
65 Robot._available_names.extend(original_pool)
66 import random
67 random.shuffle(Robot._available_names)
68
69if __name__ == '__main__':
70 unittest.main()
Test NameStatus
test_different_robots_have_different_names
Pass
test_has_name
Pass
test_name_sticks
Pass
test_reset_name
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.