|
1 | 1 | import unittest
|
2 | 2 | import networkx as nx
|
| 3 | +from synutility.SynIO.data_type import load_from_pickle |
3 | 4 | from synutility.SynGraph.Descriptor.graph_descriptors import GraphDescriptor
|
4 | 5 |
|
5 | 6 |
|
@@ -84,7 +85,9 @@ def setUp(self):
|
84 | 85 | self.graph.add_edge(35, 29, order=(0, 1.0), standard_order=-1.0)
|
85 | 86 | self.graph.add_edge(28, 29, order=(1.0, 0), standard_order=1.0)
|
86 | 87 | # Prepare the data dictionary
|
87 |
| - self.data = [{"RC": self.graph}] |
| 88 | + self.data = {"RC": self.graph, "ITS": self.graph} |
| 89 | + |
| 90 | + self.data_parallel = load_from_pickle("Data/test.pkl.gz") |
88 | 91 |
|
89 | 92 | def test_is_acyclic_graph(self):
|
90 | 93 | self.assertTrue(GraphDescriptor.is_acyclic_graph(self.acyclic_graph))
|
@@ -149,27 +152,43 @@ def test_get_element_count(self):
|
149 | 152 |
|
150 | 153 | def test_get_descriptors(self):
|
151 | 154 | # Expected output after processing
|
152 |
| - expected_output = [ |
153 |
| - { |
154 |
| - "RC": self.graph, |
155 |
| - "topo": "Single Cyclic", # Adjust based on expected graph type analysis |
156 |
| - "cycle": [ |
157 |
| - 4 |
158 |
| - ], # Expected cycle results, to be filled after actual function implementation |
159 |
| - "atom_count": {"N": 1, "H": 1, "C": 1, "Br": 1}, |
160 |
| - "rtype": "Elementary", # Expected reaction type |
161 |
| - "rstep": 1, # This should be based on the actual cycles count |
162 |
| - } |
163 |
| - ] |
| 155 | + expected_output = { |
| 156 | + "RC": self.graph, |
| 157 | + "topo": "Single Cyclic", # Adjust based on expected graph type analysis |
| 158 | + "cycle": [ |
| 159 | + 4 |
| 160 | + ], # Expected cycle results, to be filled after actual function implementation |
| 161 | + "atom_count": {"N": 1, "H": 1, "C": 1, "Br": 1}, |
| 162 | + "rtype": "Elementary", # Expected reaction type |
| 163 | + "rstep": 1, # This should be based on the actual cycles count |
| 164 | + } |
164 | 165 |
|
165 | 166 | # Run the descriptor function
|
166 |
| - GraphDescriptor.get_descriptors(self.data, "RC") |
| 167 | + results = GraphDescriptor.get_descriptors(self.data, "RC") |
| 168 | + self.assertEqual(results["topo"], expected_output["topo"]) |
| 169 | + self.assertEqual(results["cycle"], expected_output["cycle"]) |
| 170 | + self.assertEqual(results["rstep"], expected_output["rstep"]) |
| 171 | + self.assertEqual(results["atom_count"], expected_output["atom_count"]) |
| 172 | + |
| 173 | + def test_get_descriptors_parallel(self): |
| 174 | + # Expected output after processing |
| 175 | + expected_output = { |
| 176 | + "RC": self.graph, |
| 177 | + "topo": "Single Cyclic", |
| 178 | + "cycle": [4], |
| 179 | + "atom_count": {"N": 1, "H": 1, "C": 1, "Br": 1}, |
| 180 | + "rtype": "Elementary", |
| 181 | + "rstep": 1, |
| 182 | + } |
167 | 183 |
|
168 |
| - # Validate that the data has been enhanced correctly |
169 |
| - for obtained, expected in zip(self.data, expected_output): |
170 |
| - print("Hi", obtained) |
171 |
| - print("hiii", expected) |
172 |
| - self.assertDictEqual(obtained, expected) |
| 184 | + # Run the descriptor function |
| 185 | + results = GraphDescriptor.process_entries_in_parallel( |
| 186 | + self.data_parallel, "GraphRules", "ITSGraph", n_jobs=4 |
| 187 | + ) |
| 188 | + self.assertEqual(results[0]["topo"], expected_output["topo"]) |
| 189 | + self.assertEqual(results[0]["cycle"], expected_output["cycle"]) |
| 190 | + self.assertEqual(results[0]["rstep"], expected_output["rstep"]) |
| 191 | + self.assertEqual(results[0]["atom_count"], expected_output["atom_count"]) |
173 | 192 |
|
174 | 193 |
|
175 | 194 | if __name__ == "__main__":
|
|
0 commit comments