| 1 | ||
| 2 | import sys, pytest, collections, collections.abc, urllib3.exceptions, _pytest.pytester, numpy; | |
| 3 | collections.Mapping = collections.abc.Mapping; | |
| 4 | collections.MutableMapping = collections.abc.MutableMapping; | |
| 5 | collections.MutableSet = collections.abc.MutableSet; | |
| 6 | collections.Sequence = collections.abc.Sequence; | |
| 7 | collections.Callable = collections.abc.Callable; | |
| 8 | collections.Iterable = collections.abc.Iterable; | |
| 9 | collections.Iterator = collections.abc.Iterator; | |
| 10 | urllib3.exceptions.SNIMissingWarning = urllib3.exceptions.DependencyWarning; | |
| 11 | pytest.RemovedInPytest4Warning = DeprecationWarning; | |
| 12 | _pytest.pytester.Testdir = _pytest.pytester.Pytester; | |
| 13 | numpy.PINF = numpy.inf; | |
| 14 | numpy.unicode_ = numpy.str_; | |
| 15 | numpy.bytes_ = numpy.bytes_; | |
| 16 | numpy.float_ = numpy.float64; | |
| 17 | numpy.string_ = numpy.bytes_; | |
| 18 | numpy.NaN = numpy.nan; | |
| 19 | ||
| 20 | ||
| 21 | import unittest | |
| 22 | from main import Robot | |
| 23 | ||
| 24 | class 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 | ||
| 69 | if __name__ == '__main__': | |
| 70 | unittest.main() |
| Test Name | Status |
|---|---|
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.