Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/mujoco_mpc/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def parse_port(server_addr: str) -> int:
Returns:
int: the port
"""
match = re.search(r":(\d+)", server_addr)
match = re.search(r":([0-9]+)\Z", server_addr)
if match is None:
raise ValueError(f"Port not specified in server address: '{server_addr}'")
return int(match.group(1))
Expand Down
13 changes: 13 additions & 0 deletions python/mujoco_mpc/agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ def environment_reset(model, data):

class AgentTest(parameterized.TestCase):

@parameterized.parameters(
("localhost:12345", 12345),
("[::1]:12345", 12345),
("[2001:db8:12::1]:54321", 54321),
)
def test_parse_port(self, address, expected_port):
self.assertEqual(agent_lib.parse_port(address), expected_port)

@parameterized.parameters("[::1]", "localhost:123junk")
def test_parse_port_requires_terminal_port(self, address):
with self.assertRaisesRegex(ValueError, "Port not specified"):
agent_lib.parse_port(address)

def test_set_task_parameters(self):
model_path = (
pathlib.Path(__file__).parent.parent.parent
Expand Down