Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
2f7e09be
Commit
2f7e09be
authored
Feb 02, 2021
by
Bogdan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exception Handling for tests 2
parent
cba246df
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
568 additions
and
550 deletions
+568
-550
test_cluster.py
...le-stage-discovery-microservice/app/tests/test_cluster.py
+24
-20
test_cluster_result.py
...e-discovery-microservice/app/tests/test_cluster_result.py
+107
-103
test_clusterer.py
...-stage-discovery-microservice/app/tests/test_clusterer.py
+147
-141
test_similarity.py
...stage-discovery-microservice/app/tests/test_similarity.py
+290
-286
No files found.
src/data-hub/role-stage-discovery-microservice/app/tests/test_cluster.py
View file @
2f7e09be
import
unittest
try
:
import
sys
import
unittest
for
path
in
[
'../'
,
'./'
]:
import
sys
sys
.
path
.
insert
(
1
,
path
)
for
path
in
[
'../'
,
'./'
]:
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
:
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
:
except
Exception
as
e
:
print
(
e
)
print
(
e
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
except
Exception
as
e
:
print
(
"Exception found:"
)
print
(
e
)
src/data-hub/role-stage-discovery-microservice/app/tests/test_cluster_result.py
View file @
2f7e09be
import
unittest
try
:
import
sys
import
unittest
for
path
in
[
'../'
,
'./'
]:
import
sys
sys
.
path
.
insert
(
1
,
path
)
for
path
in
[
'../'
,
'./'
]:
sys
.
path
.
insert
(
1
,
path
)
# python -m unittest discover
from
processing.clustering
import
ClusterResultConverter
,
ClusterResult
# python -m unittest discover
from
typing
import
List
,
Dict
,
Any
from
processing.clustering
import
ClusterResultConverter
,
ClusterResult
from
typing
import
List
,
Dict
,
Any
class
TestClusterResult
(
unittest
.
TestCase
):
converter
:
ClusterResultConverter
=
None
class
TestClusterResult
(
unittest
.
TestCase
):
converter
:
ClusterResultConverter
=
None
def
setUp
(
self
):
try
:
def
setUp
(
self
):
self
.
converter
=
ClusterResultConverter
()
try
:
except
Exception
as
e
:
self
.
converter
=
ClusterResultConverter
()
print
(
e
)
except
Exception
as
e
:
print
(
e
)
def
test_result_undefined_feature
(
self
):
try
:
def
test_result_undefined_feature
(
self
):
cluster_groups
=
self
.
_get_some_cluster_groups_1d
()
try
:
cluster_res
=
self
.
converter
.
convert_to_cluster_results
(
cluster_groups
=
self
.
_get_some_cluster_groups_1d
()
cluster_groups
=
cluster_groups
,
cluster_res
=
self
.
converter
.
convert_to_cluster_results
(
features
=
[]
cluster_groups
=
cluster_groups
,
)
features
=
[]
)
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_len
(
cluster_groups
,
cluster_res
)
except
Exception
as
e
:
self
.
assert_correct_cluster_result_labels
([
'n.a.'
,
'n.a.'
,
'n.a.'
],
cluster_res
)
print
(
e
)
except
Exception
as
e
:
print
(
e
)
def
test_result_1d_feature
(
self
):
try
:
def
test_result_1d_feature
(
self
):
cluster_groups
=
self
.
_get_some_cluster_groups_1d
()
try
:
cluster_res
=
self
.
converter
.
convert_to_cluster_results
(
cluster_groups
=
self
.
_get_some_cluster_groups_1d
()
cluster_groups
=
cluster_groups
,
cluster_res
=
self
.
converter
.
convert_to_cluster_results
(
features
=
[
'v'
]
cluster_groups
=
cluster_groups
,
)
features
=
[
'v'
]
)
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_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
)
except
Exception
as
e
:
print
(
e
)
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
()
try
:
cluster_res
=
self
.
converter
.
convert_to_cluster_results
(
cluster_groups
=
self
.
_get_some_cluster_groups_2d
()
cluster_groups
=
cluster_groups
,
cluster_res
=
self
.
converter
.
convert_to_cluster_results
(
features
=
[
'v'
,
'u'
]
cluster_groups
=
cluster_groups
,
)
features
=
[
'v'
,
'u'
]
)
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_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
)
except
Exception
as
e
:
print
(
e
)
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
]):
try
:
def
assert_correct_cluster_result_len
(
self
,
expected
:
'original dict of lists'
,
actual
:
Dict
[
Any
,
ClusterResult
]):
self
.
assertEqual
(
len
(
expected
),
len
(
actual
))
try
:
for
i
in
range
(
len
(
expected
)):
self
.
assertEqual
(
len
(
expected
),
len
(
actual
))
self
.
assertEqual
(
len
(
expected
[
i
]),
len
(
actual
[
i
]
.
nodes
))
for
i
in
range
(
len
(
expected
)):
self
.
assertEqual
(
expected
[
i
],
actual
[
i
]
.
nodes
)
self
.
assertEqual
(
len
(
expected
[
i
]),
len
(
actual
[
i
]
.
nodes
))
self
.
assertEqual
(
expected
[
i
],
actual
[
i
]
.
nodes
)
except
Exception
as
e
:
print
(
e
)
except
Exception
as
e
:
print
(
e
)
def
assert_correct_cluster_result_labels
(
self
,
expected
:
List
[
str
],
actual
:
Dict
[
Any
,
ClusterResult
]):
try
:
def
assert_correct_cluster_result_labels
(
self
,
expected
:
List
[
str
],
actual
:
Dict
[
Any
,
ClusterResult
]):
self
.
assertEqual
(
len
(
expected
),
len
(
actual
))
try
:
for
i
in
range
(
len
(
expected
)):
self
.
assertEqual
(
len
(
expected
),
len
(
actual
))
self
.
assertEqual
(
expected
[
i
],
actual
[
i
]
.
label
)
for
i
in
range
(
len
(
expected
)):
except
Exception
as
e
:
self
.
assertEqual
(
expected
[
i
],
actual
[
i
]
.
label
)
print
(
e
)
except
Exception
as
e
:
print
(
e
)
#endregion Custom Assertions
#endregion Custom Assertions
#region helper methods
def
_get_some_cluster_groups_1d
(
self
):
#region helper methods
return
{
def
_get_some_cluster_groups_1d
(
self
):
0
:
[{
'v'
:
'0'
},
{
'v'
:
'1'
},
{
'v'
:
'-1'
}],
return
{
1
:
[{
'v'
:
'10'
},
{
'v'
:
'11'
}],
0
:
[{
'v'
:
'0'
},
{
'v'
:
'1'
},
{
'v'
:
'-1'
}],
2
:
[{
'v'
:
'2'
}],
1
:
[{
'v'
:
'10'
},
{
'v'
:
'11'
}],
}
2
:
[{
'v'
:
'2'
}],
}
def
_get_some_cluster_groups_2d
(
self
):
return
{
def
_get_some_cluster_groups_2d
(
self
):
0
:
[{
'v'
:
'0'
,
'u'
:
'0'
},
{
'v'
:
'1'
,
'u'
:
'1'
},
{
'v'
:
'-1'
,
'u'
:
'-1'
}],
return
{
1
:
[{
'v'
:
'10'
,
'u'
:
'10'
},
{
'v'
:
'11'
,
'u'
:
'11'
}],
0
:
[{
'v'
:
'0'
,
'u'
:
'0'
},
{
'v'
:
'1'
,
'u'
:
'1'
},
{
'v'
:
'-1'
,
'u'
:
'-1'
}],
2
:
[{
'v'
:
'2'
,
'u'
:
'2'
}],
1
:
[{
'v'
:
'10'
,
'u'
:
'10'
},
{
'v'
:
'11'
,
'u'
:
'11'
}],
3
:
[{
'v'
:
'7'
,
'u'
:
'7'
},
{
'v'
:
'5'
,
'u'
:
'3'
},
{
'v'
:
'-3'
,
'u'
:
'8'
}],
2
:
[{
'v'
:
'2'
,
'u'
:
'2'
}],
}
3
:
[{
'v'
:
'7'
,
'u'
:
'7'
},
{
'v'
:
'5'
,
'u'
:
'3'
},
{
'v'
:
'-3'
,
'u'
:
'8'
}],
#endregion helper methods
}
#endregion helper methods
if
__name__
==
'__main__'
:
unittest
.
main
()
if
__name__
==
'__main__'
:
\ No newline at end of file
unittest
.
main
()
except
Exception
as
e
:
print
(
"Exception found:"
)
print
(
e
)
\ No newline at end of file
src/data-hub/role-stage-discovery-microservice/app/tests/test_clusterer.py
View file @
2f7e09be
This diff is collapsed.
Click to expand it.
src/data-hub/role-stage-discovery-microservice/app/tests/test_similarity.py
View file @
2f7e09be
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment