Skip to content

Commit 46239ea

Browse files
committed
RCB-596: Sonar instructions. Copyrights. Test coverage.
1 parent 845df6a commit 46239ea

File tree

8 files changed

+103
-8
lines changed

8 files changed

+103
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,6 @@ target/
7575

7676
settings.json
7777
*.orig
78+
79+
# Sonar
80+
.scannerwork/

DEVELOPER.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
## Developer Information
22

3+
#### Sonar Scanning
4+
* Uncomment the `sonar.branch.name` line in `sonar-project.properties` and adjust the value to match your branch name.
5+
* Install the `coverage` module in to your virtual environment.
6+
```
7+
virtualenv -p python3 ~/venvs/python-binding-development
8+
source ~/venvs/python-binding-development/bin/activate
9+
pip install --upgrade pip
10+
pip install coverage
11+
```
12+
* Generate the coverage data.
13+
```
14+
coverage run --source=rosette -m pytest
15+
```
16+
* Check the results locally
17+
```
18+
coverage report
19+
```
20+
* Generate the XML coverage report
21+
```
22+
coverage xml
23+
```
24+
* Push the results to Sonar
25+
```
26+
docker run \
27+
--rm \
28+
-e SONAR_HOST_URL="${sonar_host}" \
29+
-e SONAR_LOGIN="${sonar_token}" \
30+
-v "$(pwd):/usr/src" \
31+
sonarsource/sonar-scanner-cli
32+
33+
```
34+
335
### Testing
436
To test changes you have made to the binding, you can use a pre-configured Docker environment. This environment will:
537
- Compile the binding within the container.

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
# General information about the project.
4949
project = ''
50-
copyright = '2019, Basis Technology'
50+
copyright = '2022, Basis Technology'
5151
author = 'Basis Technology'
5252

5353
# The version info for the project you're documenting, acts as replacement for

rosette/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Python client for the Rosette API.
3-
Copyright (c) 2014-2019 Basis Technology Corporation.
3+
Copyright (c) 2014-2022 Basis Technology Corporation.
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at

rosette/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
Python client for the Rosette API.
55
6-
Copyright (c) 2014-2019 Basis Technology Corporation.
6+
Copyright (c) 2014-2022 Basis Technology Corporation.
77
88
Licensed under the Apache License, Version 2.0 (the "License");
99
you may not use this file except in compliance with the License.
@@ -599,7 +599,7 @@ def set_pool_size(self, new_pool_size):
599599
if 'https:' in self.service_url:
600600
self.session.mount('https://', adapter)
601601
else:
602-
self.session.mount('http://', adapter)
602+
self.session.mount('http://', adapter) # NOSONAR
603603

604604
def __adjust_concurrency(self, dict_headers):
605605
if _CONCURRENCY_HEADER in dict_headers and dict_headers[_CONCURRENCY_HEADER] != self.max_pool_size:
@@ -947,12 +947,12 @@ def name_deduplication(self, parameters):
947947
return EndpointCaller(self, self.endpoints['NAME_DEDUPLICATION']).call(parameters)
948948

949949
def text_embedding(self, parameters):
950-
"""
950+
""" deprecated
951951
Create an L{EndpointCaller} to identify text vectors found in the texts
952952
to which it is applied and call it.
953953
@type parameters: L{DocumentParameters} or L{str}
954954
@return: A python dictionary containing the results of text embedding."""
955-
return EndpointCaller(self, self.endpoints['TEXT_EMBEDDING']).call(parameters)
955+
return self.semantic_vectors(parameters)
956956

957957
def semantic_vectors(self, parameters):
958958
"""

sonar-project.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sonar.projectKey=rosette-api-python-binding
2+
sonar.sources=rosette
3+
sonar.python.coverage.reportPaths=coverage.xml
4+
#sonar.branch.name=RCB-596-pool-size

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
"""
4-
Copyright (c) 2014-2019 Basis Technology Corporation.
4+
Copyright (c) 2014-2022 Basis Technology Corporation.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.

tests/test_rosette_api.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
"""
4-
Copyright (c) 2014-2019 Basis Technology Corporation.
4+
Copyright (c) 2014-2022 Basis Technology Corporation.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -202,6 +202,8 @@ def test_the_max_pool_size(json_response, doc_params):
202202
result = api.language(doc_params)
203203
assert result["name"] == "Rosette"
204204
assert api.get_pool_size() == 5
205+
api.set_pool_size(11)
206+
assert api.get_pool_size() == 11
205207
httpretty.disable()
206208
httpretty.reset()
207209

@@ -756,3 +758,57 @@ def test_the_similar_terms_endpoint(api, json_response, doc_params):
756758
assert result["name"] == "Rosette"
757759
httpretty.disable()
758760
httpretty.reset()
761+
762+
763+
def test_the_deprecated_endpoints(api, json_response, doc_params):
764+
"""There are three deprecated endpoints. Exercise them until they are deleted."""
765+
766+
# TEXT_EMBEDDING calls SEMANTIC_VECTORS
767+
httpretty.enable()
768+
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/semantics/vector",
769+
body=json_response, status=200, content_type="application/json")
770+
771+
result = api.text_embedding(doc_params)
772+
assert result["name"] == "Rosette"
773+
httpretty.disable()
774+
httpretty.reset()
775+
776+
# MATCHED_NAME calls NAME_SIMILARITY
777+
httpretty.enable()
778+
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
779+
body=json_response, status=200, content_type="application/json")
780+
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/name-similarity",
781+
body=json_response, status=200, content_type="application/json")
782+
783+
name_similarity_params = NameSimilarityParameters()
784+
785+
name_similarity_params["name1"] = {
786+
"text": "Michael Jackson",
787+
"language": "eng",
788+
"entityType": "PERSON"}
789+
790+
name_similarity_params["name2"] = {"text": "迈克尔·杰克逊", "entityType": "PERSON"}
791+
792+
result = api.matched_name(name_similarity_params)
793+
assert result["name"] == "Rosette"
794+
httpretty.disable()
795+
httpretty.reset()
796+
797+
# TRANSLATED_NAME calls NAME_TRANSLATION
798+
httpretty.enable()
799+
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
800+
body=json_response, status=200, content_type="application/json")
801+
httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/name-translation",
802+
body=json_response, status=200, content_type="application/json")
803+
804+
name_translation_params = NameTranslationParameters()
805+
name_translation_params["entityType"] = "PERSON"
806+
name_translation_params["targetScript"] = "Latn"
807+
name_translation_params["name"] = "some data to translate"
808+
name_translation_params["targetLanguage"] = "eng"
809+
810+
result = api.translated_name(name_translation_params)
811+
assert result["name"] == "Rosette"
812+
813+
httpretty.disable()
814+
httpretty.reset()

0 commit comments

Comments
 (0)