This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3a4431
commit 983f370
Showing
3 changed files
with
118 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "ontouml-py" | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
description = "OntoUML Python Library" | ||
license = "Apache-2.0" | ||
authors = ["Pedro Paulo F. Barcelos <[email protected]>"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import pytest | ||
|
||
from ontouml_py.classes.abstract_classes.relation import Relation | ||
from ontouml_py.classes.concrete_classes.binaryrelation import BinaryRelation | ||
from ontouml_py.classes.concrete_classes.naryrelation import NaryRelation | ||
from ontouml_py.classes.enumerations.relationstereotype import RelationStereotype | ||
|
||
|
||
def test_relation_initialization_with_valid_stereotype() -> None: | ||
"""Test the initialization of a Relation subclass with a valid stereotype.""" | ||
|
||
class BinaryRelation(Relation): | ||
def __init__(self, **data): | ||
super().__init__(**data) | ||
|
||
relation = BinaryRelation(stereotype=RelationStereotype.MATERIAL) | ||
assert ( | ||
relation.stereotype == RelationStereotype.MATERIAL | ||
), "Relation should be initialized with the specified stereotype" | ||
|
||
|
||
def test_relation_initialization_with_invalid_stereotype() -> None: | ||
"""Test the initialization of a Relation subclass with an invalid stereotype.""" | ||
|
||
class BinaryRelation(Relation): | ||
def __init__(self, **data): | ||
super().__init__(**data) | ||
|
||
with pytest.raises(ValueError): | ||
BinaryRelation(stereotype="invalid_stereotype") | ||
|
||
|
||
def test_relation_subclass_validation() -> None: | ||
"""Test the validation of allowed subclasses for Relation.""" | ||
|
||
class InvalidRelation(Relation): | ||
def __init__(self, **data): | ||
super().__init__(**data) | ||
|
||
with pytest.raises(ValueError): | ||
InvalidRelation() | ||
|
||
|
||
def test_binary_relation_as_valid_subclass() -> None: | ||
"""Test that BinaryRelation is a valid subclass of Relation.""" | ||
binary_relation = BinaryRelation() | ||
assert isinstance(binary_relation, Relation), "BinaryRelation should be a valid subclass of Relation" | ||
|
||
|
||
def test_nary_relation_as_valid_subclass() -> None: | ||
"""Test that NaryRelation is a valid subclass of Relation.""" | ||
nary_relation = NaryRelation() | ||
assert isinstance(nary_relation, Relation), "NaryRelation should be a valid subclass of Relation" | ||
|
||
|
||
def test_relation_default_values() -> None: | ||
"""Test the default values of attributes in the Relation class.""" | ||
|
||
class BinaryRelation(Relation): | ||
def __init__(self, **data): | ||
super().__init__(**data) | ||
|
||
relation = BinaryRelation() | ||
assert relation.stereotype is None, "Default value of stereotype should be None" | ||
|
||
|
||
def test_relation_attribute_assignment() -> None: | ||
"""Test attribute assignment in the Relation class.""" | ||
|
||
class BinaryRelation(Relation): | ||
def __init__(self, **data): | ||
super().__init__(**data) | ||
|
||
relation = BinaryRelation() | ||
relation.stereotype = RelationStereotype.MATERIAL | ||
assert relation.stereotype == RelationStereotype.MATERIAL, "Stereotype should be assignable in Relation class" | ||
|
||
|
||
def test_relation_initialization_with_each_stereotype() -> None: | ||
"""Test the initialization of a Relation subclass with each stereotype in RelationStereotype.""" | ||
|
||
class BinaryRelation(Relation): | ||
def __init__(self, **data): | ||
super().__init__(**data) | ||
|
||
for stereotype in RelationStereotype: | ||
relation = BinaryRelation(stereotype=stereotype) | ||
assert relation.stereotype == stereotype, f"Relation should be initialized with the stereotype {stereotype}" | ||
|
||
|
||
def test_relation_initialization_with_incorrect_type_for_stereotype() -> None: | ||
"""Test the initialization of a Relation subclass with incorrect type for stereotype.""" | ||
|
||
class BinaryRelation(Relation): | ||
def __init__(self, **data): | ||
super().__init__(**data) | ||
|
||
with pytest.raises(ValueError): | ||
BinaryRelation(stereotype=123) # Using an integer instead of a RelationStereotype member | ||
|
||
with pytest.raises(ValueError): | ||
BinaryRelation(stereotype="non_existent_stereotype") # Using a non-existent stereotype string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters