Skip to content

Commit 83b1bda

Browse files
author
khadijeh.alibabaei
committed
update the test for api
1 parent 9bb5e6a commit 83b1bda

File tree

8 files changed

+85
-28
lines changed

8 files changed

+85
-28
lines changed

.sqa/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ sqa_criteria:
2626
- qc.sec
2727

2828
environment:
29-
GIT_COMMITTER_NAME: "Lara Lloret (CSIC)"
30-
GIT_COMMITTER_EMAIL: "lloret@ifca.unican.es"
29+
GIT_COMMITTER_NAME: "Ignacio Heredia (CSIC)"
30+
GIT_COMMITTER_EMAIL: "iheredia@ifca.unican.es"
3131
LANG: C.UTF-8
3232

3333
timeout: 600
104 Bytes
Binary file not shown.

imgclas/api.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
from imgclas import paths, utils, config, test_utils
3939
from imgclas.data_utils import load_class_names, load_class_info, mount_nextcloud
4040
from imgclas.train_runfile import train_fn
41+
from pathlib import Path
4142

43+
BASE_DIR = Path(__file__).resolve().parents[1]
4244

4345
# TODO: Move to proper marshalling for arguments
4446
# The point is that some fields need additional information than the one that is contained in the config.yaml
@@ -448,33 +450,33 @@ def get_predict_args():
448450
return populate_parser(parser, default_conf)
449451

450452

451-
def get_metadata(distribution_name='imgclas'):
453+
def get_metadata():
452454
"""
453-
Function to read metadata
455+
DO NOT REMOVE - All modules should have a get_metadata() function
456+
with appropriate keys.
454457
"""
455-
456-
pkg = pkg_resources.get_distribution(distribution_name)
457-
meta = {
458-
'Name': None,
459-
'Version': None,
460-
'Summary': None,
461-
'Home-page': None,
462-
'Author': None,
463-
'Author-email': None,
464-
'License': None,
458+
distros = list(pkg_resources.find_distributions(str(BASE_DIR), only=True))
459+
if len(distros) == 0:
460+
raise Exception("No package found.")
461+
pkg = distros[0] # if several select first
462+
463+
meta_fields = {
464+
"Name": None,
465+
"Version": None,
466+
"Summary": None,
467+
"Home-page": None,
468+
"Author": None,
469+
"Author-email": None,
470+
"License": None,
465471
}
466-
472+
meta = {}
467473
for line in pkg.get_metadata_lines("PKG-INFO"):
468-
for par in meta:
469-
if line.startswith(par):
474+
# line_low = line.lower() # to avoid inconsistency due to letter cases
475+
for k in meta_fields:
476+
if line.startswith(k + ":"):
470477
_, value = line.split(": ", 1)
471-
meta[par] = value
472-
473-
# Update information with Docker info (provided as 'CONTAINER_*' env variables)
474-
r = re.compile("^CONTAINER_(.*?)$")
475-
container_vars = list(filter(r.match, list(os.environ)))
476-
for var in container_vars:
477-
meta[var.capitalize()] = os.getenv(var)
478+
meta[k] = value
479+
print(meta)
478480

479481
return meta
480482

requirements-test.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pytest
2+
pytest-xdist
3+
pytest-cov
4+
pytest-mock
5+
pytest-env
6+
flake8
7+
bandit
8+
tensorflow==1.14
9+
10+
protobuf<=3.20.1

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ python-dotenv>=0.5.1
44
numpy>=1.14.5
55
tensorboardX>=1.4
66
opencv-python>=3.4.1.4
7-
albumentations>=0.1.8
7+
albumentations[imgaug]>=0.1.8
88
tqdm>=4.25.0
99
requests>=2.18.4
1010
PyYAML>=3.12

test-requirements.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/test_api.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Its good practice to have tests checking your code runs correctly.
5+
Here we included a dummy test checking the api correctly returns
6+
expected metadata. We suggest to extend this file to include, for
7+
example, test for checking the predict() function is indeed working
8+
as expected.
9+
10+
These tests will run in the Jenkins pipeline after each change
11+
you make to the code.
12+
"""
13+
14+
import unittest
15+
16+
import imgclas.api as api
17+
18+
19+
class TestModelMethods(unittest.TestCase):
20+
def setUp(self):
21+
self.meta = api.get_metadata()
22+
23+
def test_model_metadata_type(self):
24+
"""
25+
Test that get_metadata() returns dict
26+
"""
27+
self.assertTrue(type(self.meta) is dict)
28+
29+
def test_model_metadata_values(self):
30+
"""
31+
Test that get_metadata() returns right values (subset)
32+
"""
33+
self.assertEqual(
34+
self.meta["Name"].lower().replace("-", "_"),
35+
"imgclas".lower().replace("-", "_"),
36+
)
37+
self.assertEqual(
38+
self.meta["Author"].lower(), "ignacio heredia (csic)".lower()
39+
)
40+
self.assertEqual(
41+
self.meta["License"].lower(),
42+
"apache".lower(),
43+
)
44+
45+
46+
if __name__ == "__main__":
47+
unittest.main()

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ setenv =
2525
OS_TEST_TIMEOUT=240
2626
deps =
2727
-r{toxinidir}/requirements-test.txt
28-
-r{toxinidir}/test-requirements.txt
28+
-r{toxinidir}/requirements.txt
2929

3030
[testenv:qc.sty]
3131
commands =

0 commit comments

Comments
 (0)