|
| 1 | +from model_registry.types.contexts import ModelVersion, RegisteredModel |
| 2 | + |
| 3 | + |
| 4 | +def test_model_version_repr(): |
| 5 | + """Test the repr of a ModelVersion, with name to the front, ensuring other fields are also present""" |
| 6 | + mv = ModelVersion(name="Version 1", id="123", author="test_author", description="test_description") |
| 7 | + print(mv) |
| 8 | + assert str(mv).startswith("name='Version 1'") |
| 9 | + assert "id='123'" in str(mv) |
| 10 | + assert "author='test_author'" in str(mv) |
| 11 | + assert "description='test_description'" in str(mv) |
| 12 | + print(repr(mv)) |
| 13 | + assert repr(mv).startswith("ModelVersion(name='Version 1'") |
| 14 | + assert "id='123'" in str(mv) |
| 15 | + assert "author='test_author'" in str(mv) |
| 16 | + assert "description='test_description'" in str(mv) |
| 17 | + |
| 18 | + # Test with empty name, not really used in practice but to increase coverage |
| 19 | + mv = ModelVersion(name="", id="123", author="test_author", description="test_description") |
| 20 | + print(mv) |
| 21 | + assert str(mv).startswith("name=''") |
| 22 | + assert "id='123'" in str(mv) |
| 23 | + assert "author='test_author'" in str(mv) |
| 24 | + assert "description='test_description'" in str(mv) |
| 25 | + print(repr(mv)) |
| 26 | + assert repr(mv).startswith("ModelVersion(name=''") |
| 27 | + assert "id='123'" in str(mv) |
| 28 | + assert "author='test_author'" in str(mv) |
| 29 | + assert "description='test_description'" in str(mv) |
| 30 | + |
| 31 | + |
| 32 | +def test_registered_model_repr(): |
| 33 | + """Test the repr of a RegisteredModel, with name to the front, ensuring other fields are also present""" |
| 34 | + rm = RegisteredModel(name="Model 1", id="123", owner="test_owner", description="test_description") |
| 35 | + print(rm) |
| 36 | + assert str(rm).startswith("name='Model 1'") |
| 37 | + assert "id='123'" in str(rm) |
| 38 | + assert "owner='test_owner'" in str(rm) |
| 39 | + assert "description='test_description'" in str(rm) |
| 40 | + print(repr(rm)) |
| 41 | + assert repr(rm).startswith("RegisteredModel(name='Model 1'") |
| 42 | + assert "id='123'" in str(rm) |
| 43 | + assert "owner='test_owner'" in str(rm) |
| 44 | + assert "description='test_description'" in str(rm) |
| 45 | + |
| 46 | + # Test with empty name, not really used in practice but to increase coverage |
| 47 | + rm = RegisteredModel(name="", id="123", owner="test_owner", description="test_description") |
| 48 | + print(rm) |
| 49 | + assert str(rm).startswith("name=''") |
| 50 | + assert "id='123'" in str(rm) |
| 51 | + assert "owner='test_owner'" in str(rm) |
| 52 | + assert "description='test_description'" in str(rm) |
| 53 | + print(repr(rm)) |
| 54 | + assert repr(rm).startswith("RegisteredModel(name=''") |
| 55 | + assert "id='123'" in str(rm) |
| 56 | + assert "owner='test_owner'" in str(rm) |
| 57 | + assert "description='test_description'" in str(rm) |
0 commit comments