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
4c39d6b3
Commit
4c39d6b3
authored
Jan 26, 2021
by
Bogdan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Coverage Testing Implemented
parent
26a88ef4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
169 additions
and
4 deletions
+169
-4
.gitignore
.gitignore
+2
-0
testing.py
bin/testing.py
+74
-4
test_coverage.py
...ub/role-stage-discovery-microservice/app/test_coverage.py
+93
-0
No files found.
.gitignore
View file @
4c39d6b3
...
...
@@ -17,3 +17,5 @@ src/modules/security/regular_user_credentials.json
src/modules/security/default_users.json
resources/
reports/
bin/testing.py
View file @
4c39d6b3
...
...
@@ -2,6 +2,8 @@ import os
import
sys
import
importlib.util
import
pathlib
import
shutil
import
re
'''
This script searches for all 'tests/' directories and executes all tests
...
...
@@ -10,31 +12,98 @@ It additionally installs all dependencies from a '../requirements.txt' via pip.
Use command line argument '-w' to run on windows.
'''
PY
=
sys
.
argv
[
2
]
if
(
len
(
sys
.
argv
)
>
1
and
sys
.
argv
[
1
]
==
'-py'
)
else
'python3.7'
# use -py to use your own python command
PY
=
sys
.
argv
[
2
]
if
(
len
(
sys
.
argv
)
>
1
and
sys
.
argv
[
1
]
==
'-py'
)
else
'python'
# use -py to use your own python command
COVERAGE
=
"coverage run --append --omit=*/site-packages*"
ROOT
=
pathlib
.
Path
(
__file__
)
.
parent
.
parent
.
absolute
()
REPORTS
=
ROOT
/
'reports'
TESTS_FOLDER_NAME
=
os
.
path
.
normpath
(
"/tests"
)
print
(
"
\n
Searching for tests at the path: "
+
str
(
ROOT
))
count
=
0
resultCodeList
=
[]
coverage_paths_set
=
set
()
for
(
dirname
,
dirs
,
files
)
in
os
.
walk
(
ROOT
):
#I assume all the tests are placed in a folder named "tests"
if
(
TESTS_FOLDER_NAME
in
str
(
dirname
))
\
and
'src'
in
str
(
dirname
)
\
and
not
(
f
"{TESTS_FOLDER_NAME}{os.path.normpath('/')}"
in
str
(
dirname
))
\
and
not
(
"venv"
in
str
(
dirname
)):
and
not
(
"venv"
in
str
(
dirname
))
\
and
not
(
"Lib"
in
str
(
dirname
)):
try
:
print
(
f
"Executing tests in {dirname}"
)
os
.
chdir
(
os
.
path
.
normpath
(
dirname
))
# TODO do this during docker image setup
exit_val
=
os
.
system
(
f
"{PY} -m pip install -r ../requirements.txt"
)
# install pip dependencies
exit_val
=
os
.
system
(
f
"{PY} -m unittest discover"
)
# execute the tests
#resultCodeList.append(exit_val)
#exit_val = os.system(f"{PY} -m unittest discover") # execute the tests
exit_val
=
os
.
system
(
f
"coverage run --append --omit=*/site-packages* -m unittest discover"
)
#TEST CODE COVERAGE
coverage_paths_set
.
add
(
os
.
path
.
normpath
(
dirname
))
resultCodeList
.
append
(
exit_val
)
#once per folder i.e if 3 tests are in a folder and crash, there will be just one exit val
except
Exception
as
e
:
print
(
e
)
continue
try
:
cur_dir
=
pathlib
.
Path
(
os
.
path
.
normpath
(
dirname
))
.
parent
.
absolute
()
filename_regular_expresion
=
re
.
compile
(
'(test_.*)|(TEST_.*)'
)
for
filename
in
os
.
listdir
(
cur_dir
):
if
filename_regular_expresion
.
match
(
filename
):
#gets here only if there is a test file which matches the regular expression in the app folder,
#cur_dir = os.path(dirname).parent()
os
.
chdir
(
cur_dir
)
exit_val
=
os
.
system
(
f
"coverage run --append --omit=*/site-packages* -m unittest discover"
)
coverage_paths_set
.
add
(
os
.
path
.
normpath
(
cur_dir
))
resultCodeList
.
append
(
exit_val
)
except
Exception
as
e
:
print
(
e
)
continue
#CHANGE FOLDER TO REPORTS, in order to combine the coverage
try
:
if
not
os
.
path
.
exists
(
REPORTS
):
os
.
makedirs
(
REPORTS
)
except
:
pass
os
.
chdir
(
REPORTS
)
target
=
REPORTS
target
=
str
(
target
)
+
f
'
\\
.coverage'
try
:
os
.
remove
(
target
)
#Try to Remove old coverage file, if exists
except
Exception
as
e
:
pass
print
(
"Combinging coverages"
)
counter
=
0
for
path
in
coverage_paths_set
:
try
:
path
+=
'
\\
.coverage'
original
=
path
target
=
REPORTS
target
=
str
(
target
)
+
f
'
\\
.coverage.{counter}'
counter
+=
1
shutil
.
copyfile
(
original
,
target
)
#copy new generated coverage files
os
.
remove
(
original
)
except
Exception
as
e
:
print
(
e
)
continue
print
(
"Generating Combined report"
)
os
.
system
(
"coverage combine"
)
os
.
system
(
"coverage xml"
)
os
.
system
(
"coverage html"
)
#if you want to generate the html as well
firstError
=
-
1
i
=
0
...
...
@@ -48,4 +117,5 @@ while i < len(resultCodeList):
if
(
firstError
<
0
):
#no errors found
sys
.
exit
(
0
)
else
:
sys
.
exit
(
1
)
#return code>0
\ No newline at end of file
sys
.
exit
(
1
)
#return code>0
src/data-hub/role-stage-discovery-microservice/app/test_coverage.py
0 → 100644
View file @
4c39d6b3
import
unittest
import
sys
for
path
in
[
'../'
,
'./'
]:
sys
.
path
.
insert
(
1
,
path
)
class
TestCoverage
(
unittest
.
TestCase
):
def
test_init_main
(
self
):
# python -m unittest discover
from
db.entities
import
Cluster
from
datetime
import
date
,
datetime
import
json
# add modules folder to interpreter path
import
sys
import
os
modules_path
=
'../../../modules/'
if
os
.
path
.
exists
(
modules_path
):
sys
.
path
.
insert
(
1
,
modules_path
)
### init logging ###
import
logging
LOG_FORMAT
=
(
'
%(levelname) -5
s
%(asctime)
s
%(name)
s:
%(funcName) -35
s
%(lineno) -5
d:
%(message)
s'
)
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
LOG_FORMAT
)
LOGGER
=
logging
.
getLogger
(
__name__
)
#############################
import
connexion
from
security
import
swagger_util
from
pathlib
import
Path
from
env_info
import
is_running_locally
,
get_resources_path
from
flask
import
request
from
flask
import
redirect
import
main
#error when importing main, ModuleNotFoundError: No module named 'security'
#exec(open('main.py').read())
def
test_init_run_clustering
(
self
):
import
sys
import
os
modules_path
=
'../../../modules/'
if
os
.
path
.
exists
(
modules_path
):
sys
.
path
.
insert
(
1
,
modules_path
)
import
json
from
db.entities
import
Layer
,
Cluster
from
typing
import
List
,
Dict
,
Tuple
,
Any
from
db.repository
import
Repository
from
processing.clustering
import
Clusterer
,
ClusterResult
import
run_clustering
def
test_init_run_node
(
self
):
import
sys
import
os
modules_path
=
'../../../modules/'
if
os
.
path
.
exists
(
modules_path
):
sys
.
path
.
insert
(
1
,
modules_path
)
import
json
import
urllib3
urllib3
.
disable_warnings
(
urllib3
.
exceptions
.
InsecureRequestWarning
)
import
processing.fetching.fetching
as
f
import
run_node_fetching
def
test_init_run_similarity
(
self
):
import
processing.similarityFiles.similarityMain
as
SimilarityCalc
from
db.repository
import
Repository
import
run_similarity_calc
def
test_init_run_time
(
self
):
import
sys
import
os
modules_path
=
'../../../modules/'
if
os
.
path
.
exists
(
modules_path
):
sys
.
path
.
insert
(
1
,
modules_path
)
import
json
from
datetime
import
datetime
,
date
from
db.repository
import
Repository
from
db.entities
import
ClusterSet
,
Cluster
,
Layer
,
TimeSlice
from
typing
import
Tuple
,
Dict
,
Any
,
List
import
run_time_slicing
if
__name__
==
'__main__'
:
unittest
.
main
()
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