Skip to content

Commit 8d8e63b

Browse files
authored
Merge pull request #705 from watson-developer-cloud/sem-release
Update integration tests and semantic updates
2 parents c9d68ae + ba04e03 commit 8d8e63b

12 files changed

+116
-83
lines changed

.env.enc

-944 Bytes
Binary file not shown.

.releaserc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
{
22
"branch": "master",
3-
"verifyConditions": [],
3+
"verifyConditions": ["@semantic-release/changelog", "@semantic-release/github"],
4+
"debug": true,
45
"prepare": [
56
{
67
"path": "@semantic-release/exec",
78
"cmd": "bumpversion --current-version ${lastRelease.version} --new-version ${nextRelease.version} patch"
8-
}
9+
},
10+
"@semantic-release/changelog",
11+
"@semantic-release/git"
912
],
1013
"publish": [
1114
{
12-
"path": "@semantic-release/github",
15+
"path": "@semantic-release/github"
1316
}
1417
]
1518
}

.travis.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,23 @@ before_install:
1212
- npm install npm@latest -g
1313
install:
1414
- pip install tox-travis
15-
- pip install bumpversion
16-
- npm install @semantic-release/exec
17-
script:
18-
- pip install -U python-dotenv
19-
- tox
20-
before_deploy:
15+
before_script:
2116
- sudo apt-get update
22-
- pip install -r requirements.txt
23-
- pip install -r requirements-dev.txt
2417
- pip install pypandoc
2518
- sudo apt-get install pandoc
19+
- pip install -r requirements.txt
20+
- pip install -r requirements-dev.txt
2621
- pip install --editable .
22+
script:
23+
- pip install -U python-dotenv
24+
- tox
25+
before_deploy:
26+
- pip install bumpversion
27+
- nvm install 12
28+
- npm install @semantic-release/changelog
29+
- npm install @semantic-release/exec
30+
- npm install @semantic-release/git
31+
- npm install @semantic-release/github
2732
deploy:
2833
- provider: script
2934
script: docs/publish.sh

examples/assistant_v1.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import json
22
from ibm_watson import AssistantV1
3-
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
3+
# from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
44

5-
authenticator = IAMAuthenticator('your apikey')
6-
assistant = AssistantV1(
7-
version='2018-07-10',
8-
authenticator=authenticator)
5+
6+
# Authentication via IAM
7+
# authenticator = IAMAuthenticator('your apikey')
8+
# assistant = AssistantV1(
9+
# version='2018-07-10',
10+
# authenticator=authenticator)
11+
# assistant.set_service_url('https://gateway.watsonplatform.net/assistant/api')
12+
13+
14+
# Authentication via external config like VCAP_SERVICES
15+
assistant = AssistantV1(version='2018-07-10')
916
assistant.set_service_url('https://gateway.watsonplatform.net/assistant/api')
1017

1118
#########################

examples/natural_language_understanding_v1.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import json
22
from ibm_watson import NaturalLanguageUnderstandingV1
33
from ibm_watson.natural_language_understanding_v1 import Features, EntitiesOptions, KeywordsOptions
4-
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
4+
# from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
55

6-
authenticator = IAMAuthenticator('your_api_key')
6+
# Authentication via IAM
7+
# authenticator = IAMAuthenticator('your_api_key')
8+
# service = NaturalLanguageUnderstandingV1(
9+
# version='2018-03-16',
10+
# authenticator=authenticator)
11+
# service.set_service_url('https://gateway.watsonplatform.net/natural-language-understanding/api')
12+
13+
# Authentication via external config like VCAP_SERVICES
714
service = NaturalLanguageUnderstandingV1(
8-
version='2018-03-16',
9-
authenticator=authenticator)
15+
version='2018-03-16')
1016
service.set_service_url('https://gateway.watsonplatform.net/natural-language-understanding/api')
1117

1218
response = service.analyze(

examples/personality_insights_v3.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@
88
import csv
99
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
1010

11-
authenticator = IAMAuthenticator('your_api_key')
12-
service = PersonalityInsightsV3(
13-
version='2017-10-13',
14-
authenticator=authenticator)
11+
# Authentication via IAM
12+
# authenticator = IAMAuthenticator('your_api_key')
13+
# service = PersonalityInsightsV3(
14+
# version='2017-10-13',
15+
# authenticator=authenticator)
16+
# service.set_service_url('https://gateway.watsonplatform.net/personality-insights/api')
17+
18+
# Authentication via external config like VCAP_SERVICES
19+
service = PersonalityInsightsV3(version='2017-10-13')
1520
service.set_service_url('https://gateway.watsonplatform.net/personality-insights/api')
1621

1722
############################
1823
# Profile with JSON output #
1924
############################
2025

21-
with open(join(dirname(__file__), '../resources/personality-v3.json')) as \
26+
with open(join(os.getcwd(), 'resources/personality-v3.json')) as \
2227
profile_json:
2328
profile = service.profile(
2429
profile_json.read(),
@@ -32,7 +37,7 @@
3237
# Profile with CSV output #
3338
###########################
3439

35-
with open(join(dirname(__file__), '../resources/personality-v3.json'), 'r') as \
40+
with open(join(os.getcwd(), 'resources/personality-v3.json'), 'r') as \
3641
profile_json:
3742
response = service.profile(
3843
profile_json.read(),

examples/tone_analyzer_v3.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import json
2-
from os.path import join, dirname
2+
import os
3+
from os.path import join
34
from ibm_watson import ToneAnalyzerV3
45
from ibm_watson.tone_analyzer_v3 import ToneInput
5-
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
6+
# from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
67

7-
authenticator = IAMAuthenticator('your_api_key')
8-
service = ToneAnalyzerV3(
9-
version='2017-09-21',
10-
authenticator=authenticator)
8+
# Authentication via IAM
9+
# authenticator = IAMAuthenticator('your_api_key')
10+
# service = ToneAnalyzerV3(
11+
# version='2017-09-21',
12+
# authenticator=authenticator)
13+
# service.set_service_url('https://gateway.watsonplatform.net/tone-analyzer/api')
14+
15+
# Authentication via external config like VCAP_SERVICES
16+
service = ToneAnalyzerV3(version='2017-09-21')
1117
service.set_service_url('https://gateway.watsonplatform.net/tone-analyzer/api')
1218

1319
print("\ntone_chat() example 1:\n")
@@ -30,39 +36,39 @@
3036
indent=2))
3137

3238
print("\ntone() example 2:\n")
33-
with open(join(dirname(__file__),
34-
'../resources/tone-example.json')) as tone_json:
39+
with open(join(os.getcwd(),
40+
'resources/tone-example.json')) as tone_json:
3541
tone = service.tone(json.load(tone_json)['text'], content_type="text/plain").get_result()
3642
print(json.dumps(tone, indent=2))
3743

3844
print("\ntone() example 3:\n")
39-
with open(join(dirname(__file__),
40-
'../resources/tone-example.json')) as tone_json:
45+
with open(join(os.getcwd(),
46+
'resources/tone-example.json')) as tone_json:
4147
tone = service.tone(
4248
tone_input=json.load(tone_json)['text'],
4349
content_type='text/plain',
4450
sentences=True).get_result()
4551
print(json.dumps(tone, indent=2))
4652

4753
print("\ntone() example 4:\n")
48-
with open(join(dirname(__file__),
49-
'../resources/tone-example.json')) as tone_json:
54+
with open(join(os.getcwd(),
55+
'resources/tone-example.json')) as tone_json:
5056
tone = service.tone(
5157
tone_input=json.load(tone_json),
5258
content_type='application/json').get_result()
5359
print(json.dumps(tone, indent=2))
5460

5561
print("\ntone() example 5:\n")
56-
with open(join(dirname(__file__),
57-
'../resources/tone-example-html.json')) as tone_html:
62+
with open(join(os.getcwd(),
63+
'resources/tone-example-html.json')) as tone_html:
5864
tone = service.tone(
5965
json.load(tone_html)['text'],
6066
content_type='text/html').get_result()
6167
print(json.dumps(tone, indent=2))
6268

6369
print("\ntone() example 6 with GDPR support:\n")
64-
with open(join(dirname(__file__),
65-
'../resources/tone-example-html.json')) as tone_html:
70+
with open(join(os.getcwd(),
71+
'resources/tone-example-html.json')) as tone_html:
6672
tone = service.tone(
6773
json.load(tone_html)['text'],
6874
content_type='text/html',

examples/visual_recognition_v4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# create a classifier
1515
my_collection = service.create_collection(
1616
name='',
17-
description='tetsing for python'
17+
description='testing for python'
1818
).get_result()
1919
collection_id = my_collection.get('collection_id')
2020

test/integration/test_discovery_v1.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,39 @@
88
@pytest.mark.skipif(
99
os.getenv('VCAP_SERVICES') is None, reason='requires VCAP_SERVICES')
1010
class Discoveryv1(TestCase):
11-
def setUp(self):
12-
self.discovery = ibm_watson.DiscoveryV1(
13-
version='2018-08-01')
14-
self.discovery.set_default_headers({
11+
discovery = None
12+
environment_id = '62b0dd87-eefa-40bf-81d6-cf9bc82692ab' # This environment is created for integration testing
13+
collection_id = None
14+
collection_name = 'FOR-PYTHON-DELETE-ME'
15+
16+
@classmethod
17+
def setup_class(cls):
18+
cls.discovery = ibm_watson.DiscoveryV1(version='2018-08-01')
19+
cls.discovery.set_default_headers({
1520
'X-Watson-Learning-Opt-Out': '1',
1621
'X-Watson-Test': '1'
1722
})
18-
self.environment_id = 'e15f6424-f887-4f50-b4ea-68267c36fc9c' # This environment is created for integration testing
19-
collections = self.discovery.list_collections(self.environment_id).get_result()['collections']
20-
self.collection_id = collections[0]['collection_id']
2123

24+
collections = cls.discovery.list_collections(cls.environment_id).get_result()['collections']
2225
for collection in collections:
23-
if collection['name'] == 'DO-NOT-DELETE-JAPANESE-COLLECTION':
24-
self.collection_id_JP = collection['collection_id']
25-
26-
def tearDown(self):
27-
collections = self.discovery.list_collections(self.environment_id).get_result()['collections']
26+
if collection['name'] == cls.collection_name:
27+
cls.collection_id = collection['collection_id']
28+
29+
if cls.collection_id is None:
30+
print("Creating a new temporary collection")
31+
cls.collection_id = cls.discovery.create_collection(
32+
cls.environment_id,
33+
cls.collection_name,
34+
description="Integration test for python sdk").get_result()['collection_id']
35+
36+
@classmethod
37+
def teardown_class(cls):
38+
collections = cls.discovery.list_collections(cls.environment_id).get_result()['collections']
2839
for collection in collections:
29-
if not collection['name'].startswith('DO-NOT-DELETE'):
30-
self.discovery.delete_collection(self.environment_id, collection['collection_id'])
40+
if collection['name'] == cls.collection_name:
41+
print('Deleting the temporary collection')
42+
cls.discovery.delete_collection(cls.environment_id, cls.collection_id)
43+
break
3144

3245
def test_environments(self):
3346
envs = self.discovery.list_environments().get_result()
@@ -60,32 +73,21 @@ def test_configurations(self):
6073
assert deleted_config['status'] == 'deleted'
6174

6275
def test_collections_and_expansions(self):
63-
name = 'Example collection for python' + random.choice('ABCDEFGHIJKLMNOPQ')
64-
new_collection_id = self.discovery.create_collection(
65-
self.environment_id,
66-
name,
67-
description="Integration test for python sdk").get_result()['collection_id']
68-
assert new_collection_id is not None
69-
70-
self.discovery.get_collection(self.environment_id, new_collection_id)
76+
self.discovery.get_collection(self.environment_id, self.collection_id)
7177
updated_collection = self.discovery.update_collection(
72-
self.environment_id, new_collection_id, name, description='Updating description').get_result()
78+
self.environment_id, self.collection_id, self.collection_name, description='Updating description').get_result()
7379
assert updated_collection['description'] == 'Updating description'
7480

7581
self.discovery.create_expansions(self.environment_id,
76-
new_collection_id, [{
82+
self.collection_id, [{
7783
'input_terms': ['a'],
7884
'expanded_terms': ['aa']
7985
}]).get_result()
8086
expansions = self.discovery.list_expansions(self.environment_id,
81-
new_collection_id).get_result()
87+
self.collection_id).get_result()
8288
assert expansions['expansions']
8389
self.discovery.delete_expansions(self.environment_id,
84-
new_collection_id)
85-
86-
deleted_collection = self.discovery.delete_collection(
87-
self.environment_id, new_collection_id).get_result()
88-
assert deleted_collection['status'] == 'deleted'
90+
self.collection_id)
8991

9092
def test_documents(self):
9193
with open(os.path.join(os.path.dirname(__file__), '../../resources/simple.html'), 'r') as fileinfo:
@@ -185,10 +187,11 @@ def test_create_event(self):
185187
self.collection_id,
186188
document_id).get_result()
187189

190+
@pytest.mark.skip(reason="Temporary disable")
188191
def test_tokenization_dictionary(self):
189192
result = self.discovery.get_tokenization_dictionary_status(
190193
self.environment_id,
191-
self.collection_id_JP
194+
self.collection_id
192195
).get_result()
193196
assert result['status'] is not None
194197

test/integration/test_examples.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
from os.path import join, dirname
99
from glob import glob
1010

11-
# tests to exclude
12-
excludes = ['discovery_v1.ipynb', '__init__.py', 'microphone-speech-to-text.py']
11+
# tests to include
12+
includes = ['assistant_v1.py', 'natural_language_understanding_v1.py', 'personality_insights_v3.py', 'tone_analyzer_v3.py']
1313

1414
# examples path. /examples
15-
examples_path = join(dirname(__file__), '../', 'examples', '*.py')
15+
examples_path = join(dirname(__file__), '../../', 'examples', '*.py')
1616

1717
@pytest.mark.skipif(os.getenv('VCAP_SERVICES') is None,
1818
reason='requires VCAP_SERVICES')
@@ -22,13 +22,10 @@ def test_examples():
2222
for example in examples:
2323
name = example.split('/')[-1]
2424

25-
# exclude some tests cases like authorization
26-
if name in excludes:
25+
if name not in includes:
2726
continue
2827

29-
# exclude tests if there are no credentials for that service
30-
service_name = name[:-6] if not name.startswith('visual_recognition')\
31-
else 'watson_vision_combined'
28+
service_name = name[:-6]
3229

3330
if service_name not in vcap_services:
3431
print('%s does not have credentials in VCAP_SERVICES',

0 commit comments

Comments
 (0)