|
| 1 | +import pytest |
1 | 2 | from pandas import DataFrame |
2 | 3 | from pydantic_extra_types.color import Color |
3 | 4 |
|
@@ -104,3 +105,62 @@ def test_from_dfs() -> None: |
104 | 105 | assert VG.relationships[1].source == 1 |
105 | 106 | assert VG.relationships[1].target == 0 |
106 | 107 | assert VG.relationships[1].caption == "REL2" |
| 108 | + |
| 109 | + |
| 110 | +def test_node_errors() -> None: |
| 111 | + nodes = DataFrame( |
| 112 | + {"caption": ["A", "B"], "size": [1337, 42], "color": "#FF0000", "instrument": ["piano", "guitar"]} |
| 113 | + ) |
| 114 | + with pytest.raises( |
| 115 | + ValueError, |
| 116 | + match=r"Mandatory column 'id' is missing. Expected one of \['id', 'ID', 'id', 'nodeid', 'NODEID', 'nodeid', 'node_id', 'NODE_ID', 'nodeId'\] to be present", |
| 117 | + ): |
| 118 | + from_dfs(nodes, []) |
| 119 | + |
| 120 | + nodes = DataFrame( |
| 121 | + { |
| 122 | + "id": [0, 1], |
| 123 | + "caption": ["A", "B"], |
| 124 | + "size": ["aaa", 42], |
| 125 | + "color": "#FF0000", |
| 126 | + "instrument": ["piano", "guitar"], |
| 127 | + } |
| 128 | + ) |
| 129 | + with pytest.raises( |
| 130 | + ValueError, |
| 131 | + match=r"Error for column 'size' with provided input 'aaa'. Reason: Input should be a valid integer, unable to parse string as an integer", |
| 132 | + ): |
| 133 | + from_dfs(nodes, []) |
| 134 | + |
| 135 | + |
| 136 | +def test_rel_errors() -> None: |
| 137 | + nodes = DataFrame( |
| 138 | + {"id": [0, 1], "caption": ["A", "B"], "size": [1337, 42], "color": "#FF0000", "instrument": ["piano", "guitar"]} |
| 139 | + ) |
| 140 | + relationships = DataFrame( |
| 141 | + { |
| 142 | + "target": [1, 0], |
| 143 | + "caption": ["REL", "REL2"], |
| 144 | + "weight": [1.0, 2.0], |
| 145 | + } |
| 146 | + ) |
| 147 | + with pytest.raises( |
| 148 | + ValueError, |
| 149 | + match=r"Mandatory column 'source' is missing. Expected one of \['source', 'SOURCE', 'source', 'sourcenodeid', 'SOURCENODEID', 'sourcenodeid', 'source_node_id', 'SOURCE_NODE_ID', 'sourceNodeId', 'from', 'FROM', 'from'\] to be present", |
| 150 | + ): |
| 151 | + from_dfs(nodes, relationships) |
| 152 | + |
| 153 | + relationships = DataFrame( |
| 154 | + { |
| 155 | + "source": [0, 1], |
| 156 | + "target": [1, 0], |
| 157 | + "caption": ["REL", "REL2"], |
| 158 | + "caption_size": [1.0, -300], |
| 159 | + "weight": [1.0, 2.0], |
| 160 | + } |
| 161 | + ) |
| 162 | + with pytest.raises( |
| 163 | + ValueError, |
| 164 | + match=r"Error for column 'caption_size' with provided input '-300.0'. Reason: Input should be greater than 0", |
| 165 | + ): |
| 166 | + from_dfs(nodes, relationships) |
0 commit comments