Skip to content

Commit 630a8b3

Browse files
authored
Added tests in hydra python core. (#93)
* created conftest * test_context * test_hydra_class * test_hydra_collection * test_hydraentrypoint * changed travis and requirements * python 3.8 in travis
1 parent fe18d88 commit 630a8b3

9 files changed

Lines changed: 514 additions & 168 deletions

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
language: python
22
python:
3-
- "3.5"
4-
- "3.5-dev" # 3.5 development branch
53
- "3.6"
6-
- "3.6-dev" # 3.6 development branch
7-
- "3.7-dev"
4+
- "3.6-dev" # 3.6 development branch
5+
- "3.7"
6+
- "3.7-dev" # 3.7 development branch
7+
- "3.8"
8+
- "3.8-dev"
89
install:
910
- pip install -r requirements-dev.txt --no-cache
10-
script: python -m unittest discover
11+
script: pytest

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pep8==1.7.1
22
pyld==2.0.3
3+
pytest==6.2.4
34
requests

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pyld
22
requests
3-
sphinx==3.1.2
3+
sphinx==3.1.2
4+
pytest==6.2.4

tests/conftest.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import pytest
2+
from hydra_python_core.doc_writer import HydraClass
3+
from hydra_python_core.doc_writer import HydraEntryPoint
4+
from hydra_python_core.doc_writer import HydraCollection
5+
from hydra_python_core.doc_writer import Context
6+
from samples import doc_writer_sample_output
7+
8+
@pytest.fixture(name="get_hydra_class")
9+
def get_hydra_class():
10+
# Creating classes for the API
11+
class_title = "dummyClass" # Title of the Class
12+
class_description = "A dummyClass for demo" # Description of the class
13+
class_ = HydraClass(class_title, class_description, endpoint=False)
14+
return class_
15+
16+
@pytest.fixture(name="get_hydra_entrypoint")
17+
def get_hydraentrypoint():
18+
#Creating HydraEntrypoint
19+
base_url = "http://www.hydrus.com/"
20+
entrypoint = "test_api"
21+
hydra_entrypoint = HydraEntryPoint(base_url,entrypoint)
22+
return hydra_entrypoint
23+
24+
@pytest.fixture(name="get_hydra_collection")
25+
def get_hydra_collection(get_hydra_class):
26+
#Creating HydraEntrypoint
27+
class_ = get_hydra_class
28+
collection_title = "dummyClass collection"
29+
collection_name = "dummyclasses"
30+
collection_description = "This collection comprises of instances of dummyClass"
31+
collection_managed_by = {
32+
"property": "rdf:type",
33+
"object": class_.id_,
34+
}
35+
36+
collection_ = HydraCollection(collection_name=collection_name,
37+
collection_description=collection_description, manages=collection_managed_by, get=True,
38+
post=True, collection_path="DcTest")
39+
return collection_
40+
41+
@pytest.fixture(name="get_context")
42+
def get_context():
43+
context = Context('https://hydrus.com/')
44+
return context
45+
46+
@pytest.fixture(name="get_doc")
47+
def get_doc():
48+
doc = doc_writer_sample_output.doc
49+
return doc

tests/test_doc_writer.py

Lines changed: 0 additions & 162 deletions
This file was deleted.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import unittest
2+
from hydra_python_core.doc_writer import Context
3+
from unittest.mock import MagicMock, patch
4+
5+
6+
class TestContext:
7+
8+
def test_context_with_nothing(self, get_context):
9+
"""
10+
Test method to test if correct context is generated when no arguments are passed
11+
12+
"""
13+
context = get_context
14+
expected_context = {
15+
'hydra': 'http://www.w3.org/ns/hydra/core#',
16+
'property': {
17+
'@type': '@id',
18+
'@id': 'hydra:property'
19+
},
20+
'supportedClass': 'hydra:supportedClass',
21+
'supportedProperty': 'hydra:supportedProperty',
22+
'supportedOperation': 'hydra:supportedOperation',
23+
'label': 'rdfs:label',
24+
'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
25+
"xsd": "https://www.w3.org/TR/xmlschema-2/#",
26+
'domain': {
27+
'@type': '@id',
28+
'@id': 'rdfs:domain'
29+
},
30+
'ApiDocumentation': 'hydra:ApiDocumentation',
31+
'range': {
32+
'@type': '@id',
33+
'@id': 'rdfs:range'
34+
},
35+
'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
36+
'title': 'hydra:title',
37+
'expects': {
38+
'@type': '@id',
39+
'@id': 'hydra:expects'
40+
},
41+
'returns': {
42+
'@id': 'hydra:returns',
43+
'@type': '@id'
44+
},
45+
'entrypoint': {
46+
'@id': 'hydra:entrypoint',
47+
'@type': '@id'
48+
},
49+
'object': {
50+
'@id': 'hydra:object',
51+
'@type': '@id'
52+
},
53+
'subject': {
54+
'@id': 'hydra:subject',
55+
'@type': '@id'
56+
},
57+
'readable': 'hydra:readable',
58+
'writeable': 'hydra:writeable',
59+
'possibleStatus': 'hydra:possibleStatus',
60+
'required': 'hydra:required',
61+
'method': 'hydra:method',
62+
'statusCode': 'hydra:statusCode',
63+
'description': 'hydra:description',
64+
'expectsHeader': 'hydra:expectsHeader',
65+
'returnsHeader': 'hydra:returnsHeader',
66+
'manages': 'hydra:manages',
67+
'subClassOf': {
68+
'@id': 'rdfs:subClassOf',
69+
'@type': '@id'
70+
},
71+
'search': 'hydra:search'
72+
}
73+
assert expected_context == context.generate()
74+
75+
def test_context_with_entrypoint(self, capsys, get_hydra_entrypoint):
76+
_entrypoint = get_hydra_entrypoint
77+
context = Context("http://www.hydrus.com/", entrypoint=_entrypoint)
78+
expected_context = {'EntryPoint': 'http://hydrus.com/test_api/vocab?resource=EntryPoint'}
79+
assert expected_context == context.generate()
80+
81+
def test_context_with_class(self, capsys, get_hydra_class):
82+
_class = get_hydra_class
83+
context = Context("http://www.hydrus.com/", class_=_class)
84+
expected_context = {
85+
'hydra': 'http://www.w3.org/ns/hydra/core#',
86+
'members': 'http://www.w3.org/ns/hydra/core#member',
87+
'object': 'http://schema.org/object',
88+
'dummyClass': 'http://hydrus.com/test_api/vocab?resource=dummyClass'
89+
}
90+
assert expected_context == context.generate()
91+
92+
def test_context_with_collection(self, capsys, get_hydra_collection):
93+
collection_ = get_hydra_collection
94+
context = Context("http://www.hydrus.com/", collection=collection_)
95+
expected_context = {
96+
'hydra': 'http://www.w3.org/ns/hydra/core#',
97+
'members': 'http://www.w3.org/ns/hydra/core#member',
98+
'dummyclasses': 'http://hydrus.com/test_api/vocab?resource=dummyclasses'
99+
}
100+
assert expected_context == context.generate()

0 commit comments

Comments
 (0)