Commit f6af0a8e authored by Bogdan's avatar Bogdan

Refactored Test Code

parent 4c4c978a
...@@ -3,7 +3,9 @@ import sys ...@@ -3,7 +3,9 @@ import sys
for path in ['../', './']: for path in ['../', './']:
sys.path.insert(1, path) sys.path.insert(1, path)
#####################################
### Don't include for test report ###
#####################################
try: try:
class TestCoverage(unittest.TestCase): class TestCoverage(unittest.TestCase):
def test_init_main(self): def test_init_main(self):
......
try:
import unittest import unittest
import sys import sys
for path in ['../', './']: for path in ['../', './']:
sys.path.insert(1, path) sys.path.insert(1, path)
# python -m unittest discover # python -m unittest discover
from db.entities import Cluster from db.entities import Cluster
from datetime import date, datetime from datetime import date, datetime
import json import json
class TestCluster(unittest.TestCase): class TestCluster(unittest.TestCase):
def test_init_Cluster(self): def test_init_Cluster(self):
try:
c = Cluster('debug', 'debug-table1', 'layer1', 1, [1, 2, 3]) c = Cluster('debug', 'debug-table1', 'layer1', 1, [1, 2, 3])
self.assertEqual('debug', c.use_case) self.assertEqual('debug', c.use_case)
self.assertEqual('debug-table1', c.use_case_table) self.assertEqual('debug-table1', c.use_case_table)
self.assertEqual(1, c.cluster_label) self.assertEqual(1, c.cluster_label)
self.assertEqual([1, 2, 3], c.nodes) self.assertEqual([1, 2, 3], c.nodes)
except Exception as e:
print(e)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
except Exception as e:
print ("Exception found:")
print (e)
try: import unittest
import unittest import sys
import sys for path in ['../', './']:
for path in ['../', './']:
sys.path.insert(1, path) sys.path.insert(1, path)
# python -m unittest discover # python -m unittest discover
from processing.clustering import ClusterResultConverter, ClusterResult from processing.clustering import ClusterResultConverter, ClusterResult
from typing import List, Dict, Any from typing import List, Dict, Any
class TestClusterResult(unittest.TestCase): class TestClusterResult(unittest.TestCase):
converter:ClusterResultConverter = None converter:ClusterResultConverter = None
def setUp(self): def setUp(self):
try:
self.converter = ClusterResultConverter() self.converter = ClusterResultConverter()
except Exception as e:
print (e)
def test_result_undefined_feature(self): def test_result_undefined_feature(self):
try:
cluster_groups = self._get_some_cluster_groups_1d() cluster_groups = self._get_some_cluster_groups_1d()
cluster_res = self.converter.convert_to_cluster_results( cluster_res = self.converter.convert_to_cluster_results(
cluster_groups=cluster_groups, cluster_groups=cluster_groups,
...@@ -27,11 +24,8 @@ try: ...@@ -27,11 +24,8 @@ try:
self.assert_correct_cluster_result_len(cluster_groups, cluster_res) self.assert_correct_cluster_result_len(cluster_groups, cluster_res)
self.assert_correct_cluster_result_labels(['n.a.','n.a.','n.a.'], cluster_res) self.assert_correct_cluster_result_labels(['n.a.','n.a.','n.a.'], cluster_res)
except Exception as e:
print (e)
def test_result_1d_feature(self): def test_result_1d_feature(self):
try:
cluster_groups = self._get_some_cluster_groups_1d() cluster_groups = self._get_some_cluster_groups_1d()
cluster_res = self.converter.convert_to_cluster_results( cluster_res = self.converter.convert_to_cluster_results(
cluster_groups=cluster_groups, cluster_groups=cluster_groups,
...@@ -42,12 +36,8 @@ try: ...@@ -42,12 +36,8 @@ try:
self.assert_correct_cluster_result_len(cluster_groups, cluster_res) self.assert_correct_cluster_result_len(cluster_groups, cluster_res)
self.assert_correct_cluster_result_labels(['-1.0 -- 1.0','10.0 -- 11.0','2.0 -- 2.0'], cluster_res) self.assert_correct_cluster_result_labels(['-1.0 -- 1.0','10.0 -- 11.0','2.0 -- 2.0'], cluster_res)
except Exception as e:
print (e)
def test_result_2d_features(self): def test_result_2d_features(self):
try:
cluster_groups = self._get_some_cluster_groups_2d() cluster_groups = self._get_some_cluster_groups_2d()
cluster_res = self.converter.convert_to_cluster_results( cluster_res = self.converter.convert_to_cluster_results(
cluster_groups=cluster_groups, cluster_groups=cluster_groups,
...@@ -57,29 +47,21 @@ try: ...@@ -57,29 +47,21 @@ try:
self.assert_correct_cluster_result_len(cluster_groups, cluster_res) self.assert_correct_cluster_result_len(cluster_groups, cluster_res)
self.assert_correct_cluster_result_labels([str((0.0,0.0)), str((10.5,10.5)), str((2.0,2.0)), str((3.0,6.0))], cluster_res) self.assert_correct_cluster_result_labels([str((0.0,0.0)), str((10.5,10.5)), str((2.0,2.0)), str((3.0,6.0))], cluster_res)
except Exception as e:
print (e)
#region Custom Assertions #region Custom Assertions
def assert_correct_cluster_result_len(self, expected: 'original dict of lists', actual: Dict[Any, ClusterResult]): def assert_correct_cluster_result_len(self, expected: 'original dict of lists', actual: Dict[Any, ClusterResult]):
try:
self.assertEqual(len(expected), len(actual)) self.assertEqual(len(expected), len(actual))
for i in range(len(expected)): for i in range(len(expected)):
self.assertEqual(len(expected[i]), len(actual[i].nodes)) self.assertEqual(len(expected[i]), len(actual[i].nodes))
self.assertEqual(expected[i], actual[i].nodes) self.assertEqual(expected[i], actual[i].nodes)
except Exception as e:
print (e)
def assert_correct_cluster_result_labels(self, expected: List[str], actual: Dict[Any, ClusterResult]): def assert_correct_cluster_result_labels(self, expected: List[str], actual: Dict[Any, ClusterResult]):
try:
self.assertEqual(len(expected), len(actual)) self.assertEqual(len(expected), len(actual))
for i in range(len(expected)): for i in range(len(expected)):
self.assertEqual(expected[i], actual[i].label) self.assertEqual(expected[i], actual[i].label)
except Exception as e:
print (e)
#endregion Custom Assertions #endregion Custom Assertions
...@@ -100,8 +82,5 @@ try: ...@@ -100,8 +82,5 @@ try:
} }
#endregion helper methods #endregion helper methods
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
\ No newline at end of file
except Exception as e:
print ("Exception found:")
print (e)
\ No newline at end of file
try:
import unittest import unittest
import sys import sys
for path in ['../', './']: for path in ['../', './']:
sys.path.insert(1, path) sys.path.insert(1, path)
# python -m unittest discover # python -m unittest discover
from processing.clustering import Clusterer, ClusterResult from processing.clustering import Clusterer, ClusterResult
import numpy as np import numpy as np
from typing import List, Dict, Any from typing import List, Dict, Any
class TestClusterer(unittest.TestCase): class TestClusterer(unittest.TestCase):
clusterer:Clusterer = None clusterer:Clusterer = None
def setUp(self): def setUp(self):
...@@ -193,8 +193,6 @@ try: ...@@ -193,8 +193,6 @@ try:
#endregion helper methods #endregion helper methods
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
except Exception as e:
print ("Exception found:")
print (e)
try: import unittest
import unittest
import sys import sys
for path in ['../', './', '../../../modules/', '../../../../modules']: for path in ['../', './', '../../../modules/', '../../../../modules']:
sys.path.insert(1, path) sys.path.insert(1, path)
from db.entities.connected_node import NodeC from db.entities.connected_node import NodeC
from db.entities.connected_cluster import ClusterC from db.entities.connected_cluster import ClusterC
from db.entities.connected_layer import LayerC from db.entities.connected_layer import LayerC
import math import math
import datetime import datetime
from typing import Dict from typing import Dict
from typing import Dict from typing import Dict
from processing.similarityFiles.dataInput import * from processing.similarityFiles.dataInput import *
from processing.similarityFiles.calculateWeights import * from processing.similarityFiles.calculateWeights import *
from processing.similarityFiles.calculateSimilarity import * from processing.similarityFiles.calculateSimilarity import *
from processing.similarityFiles.miscFunctions import * from processing.similarityFiles.miscFunctions import *
import json import json
class TestSimilarity(unittest.TestCase): class TestSimilarity(unittest.TestCase):
'''Tests the similarity calculation which works without object orientation.''' '''Tests the similarity calculation which works without object orientation.'''
def test_integration_similarityCalculation(self): def test_integration_calculateSimilarity_ClustersDict_CorrectValue(self):
''' '''
Only for testing, can be deleted at any time.\n Only for testing, can be deleted at any time.\n
Served as a testing example to make sure the computations are correct Served as a testing example to make sure the computations are correct
...@@ -68,7 +67,7 @@ try: ...@@ -68,7 +67,7 @@ try:
def getTestLocationLayerData(): def getTestLocationLayerData():
inputLayerLocation = [ inputLayerLocation = [
{ {
"cluster_label": 1, "cluster_label": 1,
...@@ -199,7 +198,7 @@ try: ...@@ -199,7 +198,7 @@ try:
] ]
return inputLayerLocation return inputLayerLocation
def getTestTimeLayerData(): def getTestTimeLayerData():
inputLayerTime = [ inputLayerTime = [
{ {
"cluster_label": 4, "cluster_label": 4,
...@@ -298,7 +297,7 @@ try: ...@@ -298,7 +297,7 @@ try:
] ]
return inputLayerTime return inputLayerTime
def getTestPriceLayerData(): def getTestPriceLayerData():
inputLayerPrice = [ inputLayerPrice = [
{ {
"cluster_label": 6, "cluster_label": 6,
...@@ -398,8 +397,5 @@ try: ...@@ -398,8 +397,5 @@ try:
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
\ No newline at end of file
except Exception as e:
print ("Exception found:")
print (e)
\ No newline at end of file
...@@ -3,7 +3,9 @@ import sys ...@@ -3,7 +3,9 @@ import sys
for path in ['../', './']: for path in ['../', './']:
sys.path.insert(1, path) sys.path.insert(1, path)
#####################################
### Don't include for test report ###
#####################################
try: try:
class TestCoverage(unittest.TestCase): class TestCoverage(unittest.TestCase):
def test_init_main(self): def test_init_main(self):
......
...@@ -67,8 +67,8 @@ class Test_Pipeline(unittest.TestCase): ...@@ -67,8 +67,8 @@ class Test_Pipeline(unittest.TestCase):
} }
} }
} }
#original name testTraceProcessing
def testTraceProcessing(self): def test_handle_new_trace_newTraceMsg_correctlyInserted(self):
msg = self._buildTraceMessage() msg = self._buildTraceMessage()
self.handler.handle_new_trace(msg["content"]) self.handler.handle_new_trace(msg["content"])
self.assertEqual(len(self.handler._repository.layernodes),1) self.assertEqual(len(self.handler._repository.layernodes),1)
......
...@@ -3,7 +3,9 @@ import sys ...@@ -3,7 +3,9 @@ import sys
for path in ['../', './']: for path in ['../', './']:
sys.path.insert(1, path) sys.path.insert(1, path)
#####################################
### Don't include for test report ###
#####################################
try: try:
class TestCoverage(unittest.TestCase): class TestCoverage(unittest.TestCase):
def test_init_main(self): def test_init_main(self):
......
...@@ -4,7 +4,7 @@ from db.entities.layer_adapter import LayerAdapter ...@@ -4,7 +4,7 @@ from db.entities.layer_adapter import LayerAdapter
class Test_Layer_Adapter(unittest.TestCase): class Test_Layer_Adapter(unittest.TestCase):
def test_valid_adapter(self): def test_LayerAdapter_newLayerAdapterObj_validInstantiation(self):
adapter1 = LayerAdapter("layer1", "use_case", "table", ["a", "c"], ["a"]) adapter1 = LayerAdapter("layer1", "use_case", "table", ["a", "c"], ["a"])
print(adapter1.to_serializable_dict) print(adapter1.to_serializable_dict)
......
...@@ -2,6 +2,11 @@ import unittest ...@@ -2,6 +2,11 @@ import unittest
import sys import sys
for path in ['../', './']: for path in ['../', './']:
sys.path.insert(1, path) sys.path.insert(1, path)
#####################################
### Don't include for test report ###
#####################################
try: try:
class TestCoverage(unittest.TestCase): class TestCoverage(unittest.TestCase):
def test_init_main(self): def test_init_main(self):
......
...@@ -3,6 +3,10 @@ import sys ...@@ -3,6 +3,10 @@ import sys
for path in ['../', './']: for path in ['../', './']:
sys.path.insert(1, path) sys.path.insert(1, path)
#####################################
### Don't include for test report ###
#####################################
try: try:
class TestCoverage(unittest.TestCase): class TestCoverage(unittest.TestCase):
def test_init_main(self): def test_init_main(self):
......
...@@ -170,7 +170,7 @@ class Test_MessageHandler(unittest.TestCase): ...@@ -170,7 +170,7 @@ class Test_MessageHandler(unittest.TestCase):
self.assertEqual('semantic-linking', self.msg_sender.last_message['key']) self.assertEqual('semantic-linking', self.msg_sender.last_message['key'])
self.assertEqual('new-trace', json.loads(self.msg_sender.last_message['msg'])["type"]) self.assertEqual('new-trace', json.loads(self.msg_sender.last_message['msg'])["type"])
def test_handleblockchain_duplicateTrace(self): def test_handleBlockchainTransaction_duplicateTrace_oneTransAddedToDuplicateRepo(self):
msg = self._get_valid_message() msg = self._get_valid_message()
msg2 = self._get_valid_message() msg2 = self._get_valid_message()
msg = eval(msg) msg = eval(msg)
...@@ -179,7 +179,7 @@ class Test_MessageHandler(unittest.TestCase): ...@@ -179,7 +179,7 @@ class Test_MessageHandler(unittest.TestCase):
self.handler.handle_blockchain_transaction(msg2['content']) self.handler.handle_blockchain_transaction(msg2['content'])
self.assertEqual(len(self.repo.added_transactions),len(self.repo.duplicated_transactions)) self.assertEqual(len(self.repo.added_transactions),len(self.repo.duplicated_transactions))
def test_handleblockchain_duplicateTraceDifferentTable(self): def test_handleBlockchainTransaction_duplicateTraceDifferentTable_bothTransactionsAddedAsUnique(self):
msg = self._get_valid_message() msg = self._get_valid_message()
msg2 = self._get_valid_message2() msg2 = self._get_valid_message2()
msg = eval(msg) msg = eval(msg)
...@@ -188,7 +188,7 @@ class Test_MessageHandler(unittest.TestCase): ...@@ -188,7 +188,7 @@ class Test_MessageHandler(unittest.TestCase):
self.handler.handle_blockchain_transaction(msg2['content']) self.handler.handle_blockchain_transaction(msg2['content'])
self.assertEqual(len(self.repo.added_transactions),2) self.assertEqual(len(self.repo.added_transactions),2)
def test_handleblockchain_duplicateTraceDifferentUseCase(self): def test_handleBlockchainTransaction_duplicateTraceDifferentUseCase_bothTransactionsAddedAsUnique(self):
msg = self._get_valid_message() msg = self._get_valid_message()
msg2 = self._get_valid_message3() msg2 = self._get_valid_message3()
msg = eval(msg) msg = eval(msg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment