Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .env.enc
Binary file not shown.
9 changes: 6 additions & 3 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"branch": "master",
"verifyConditions": [],
"verifyConditions": ["@semantic-release/changelog", "@semantic-release/github"],
"debug": true,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably don't need the "debug" field here, but also ok to leave it you want... I think it just results in more output in the travis build log

"prepare": [
{
"path": "@semantic-release/exec",
"cmd": "bumpversion --current-version ${lastRelease.version} --new-version ${nextRelease.version} patch"
}
},
"@semantic-release/changelog",
"@semantic-release/git"
],
"publish": [
{
"path": "@semantic-release/github",
"path": "@semantic-release/github"
}
]
}
21 changes: 13 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ before_install:
- npm install npm@latest -g
install:
- pip install tox-travis
- pip install bumpversion
- npm install @semantic-release/exec
script:
- pip install -U python-dotenv
- tox
before_deploy:
before_script:
- sudo apt-get update
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- pip install pypandoc
- sudo apt-get install pandoc
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- pip install --editable .
script:
- pip install -U python-dotenv
- tox
before_deploy:
- pip install bumpversion
- nvm install 12
- npm install @semantic-release/changelog
- npm install @semantic-release/exec
- npm install @semantic-release/git
- npm install @semantic-release/github
deploy:
- provider: script
script: docs/publish.sh
Expand Down
17 changes: 12 additions & 5 deletions examples/assistant_v1.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import json
from ibm_watson import AssistantV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
# from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('your apikey')
assistant = AssistantV1(
version='2018-07-10',
authenticator=authenticator)

# Authentication via IAM
# authenticator = IAMAuthenticator('your apikey')
# assistant = AssistantV1(
# version='2018-07-10',
# authenticator=authenticator)
# assistant.set_service_url('https://gateway.watsonplatform.net/assistant/api')


# Authentication via external config like VCAP_SERVICES
assistant = AssistantV1(version='2018-07-10')
assistant.set_service_url('https://gateway.watsonplatform.net/assistant/api')

#########################
Expand Down
14 changes: 10 additions & 4 deletions examples/natural_language_understanding_v1.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import json
from ibm_watson import NaturalLanguageUnderstandingV1
from ibm_watson.natural_language_understanding_v1 import Features, EntitiesOptions, KeywordsOptions
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
# from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('your_api_key')
# Authentication via IAM
# authenticator = IAMAuthenticator('your_api_key')
# service = NaturalLanguageUnderstandingV1(
# version='2018-03-16',
# authenticator=authenticator)
# service.set_service_url('https://gateway.watsonplatform.net/natural-language-understanding/api')

# Authentication via external config like VCAP_SERVICES
service = NaturalLanguageUnderstandingV1(
version='2018-03-16',
authenticator=authenticator)
version='2018-03-16')
service.set_service_url('https://gateway.watsonplatform.net/natural-language-understanding/api')

response = service.analyze(
Expand Down
17 changes: 11 additions & 6 deletions examples/personality_insights_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@
import csv
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('your_api_key')
service = PersonalityInsightsV3(
version='2017-10-13',
authenticator=authenticator)
# Authentication via IAM
# authenticator = IAMAuthenticator('your_api_key')
# service = PersonalityInsightsV3(
# version='2017-10-13',
# authenticator=authenticator)
# service.set_service_url('https://gateway.watsonplatform.net/personality-insights/api')

# Authentication via external config like VCAP_SERVICES
service = PersonalityInsightsV3(version='2017-10-13')
service.set_service_url('https://gateway.watsonplatform.net/personality-insights/api')

############################
# Profile with JSON output #
############################

with open(join(dirname(__file__), '../resources/personality-v3.json')) as \
with open(join(os.getcwd(), 'resources/personality-v3.json')) as \
profile_json:
profile = service.profile(
profile_json.read(),
Expand All @@ -32,7 +37,7 @@
# Profile with CSV output #
###########################

with open(join(dirname(__file__), '../resources/personality-v3.json'), 'r') as \
with open(join(os.getcwd(), 'resources/personality-v3.json'), 'r') as \
profile_json:
response = service.profile(
profile_json.read(),
Expand Down
38 changes: 22 additions & 16 deletions examples/tone_analyzer_v3.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import json
from os.path import join, dirname
import os
from os.path import join
from ibm_watson import ToneAnalyzerV3
from ibm_watson.tone_analyzer_v3 import ToneInput
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
# from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('your_api_key')
service = ToneAnalyzerV3(
version='2017-09-21',
authenticator=authenticator)
# Authentication via IAM
# authenticator = IAMAuthenticator('your_api_key')
# service = ToneAnalyzerV3(
# version='2017-09-21',
# authenticator=authenticator)
# service.set_service_url('https://gateway.watsonplatform.net/tone-analyzer/api')

# Authentication via external config like VCAP_SERVICES
service = ToneAnalyzerV3(version='2017-09-21')
service.set_service_url('https://gateway.watsonplatform.net/tone-analyzer/api')

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

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

print("\ntone() example 3:\n")
with open(join(dirname(__file__),
'../resources/tone-example.json')) as tone_json:
with open(join(os.getcwd(),
'resources/tone-example.json')) as tone_json:
tone = service.tone(
tone_input=json.load(tone_json)['text'],
content_type='text/plain',
sentences=True).get_result()
print(json.dumps(tone, indent=2))

print("\ntone() example 4:\n")
with open(join(dirname(__file__),
'../resources/tone-example.json')) as tone_json:
with open(join(os.getcwd(),
'resources/tone-example.json')) as tone_json:
tone = service.tone(
tone_input=json.load(tone_json),
content_type='application/json').get_result()
print(json.dumps(tone, indent=2))

print("\ntone() example 5:\n")
with open(join(dirname(__file__),
'../resources/tone-example-html.json')) as tone_html:
with open(join(os.getcwd(),
'resources/tone-example-html.json')) as tone_html:
tone = service.tone(
json.load(tone_html)['text'],
content_type='text/html').get_result()
print(json.dumps(tone, indent=2))

print("\ntone() example 6 with GDPR support:\n")
with open(join(dirname(__file__),
'../resources/tone-example-html.json')) as tone_html:
with open(join(os.getcwd(),
'resources/tone-example-html.json')) as tone_html:
tone = service.tone(
json.load(tone_html)['text'],
content_type='text/html',
Expand Down
2 changes: 1 addition & 1 deletion examples/visual_recognition_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# create a classifier
my_collection = service.create_collection(
name='',
description='tetsing for python'
description='testing for python'
).get_result()
collection_id = my_collection.get('collection_id')

Expand Down
65 changes: 34 additions & 31 deletions test/integration/test_discovery_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,39 @@
@pytest.mark.skipif(
os.getenv('VCAP_SERVICES') is None, reason='requires VCAP_SERVICES')
class Discoveryv1(TestCase):
def setUp(self):
self.discovery = ibm_watson.DiscoveryV1(
version='2018-08-01')
self.discovery.set_default_headers({
discovery = None
environment_id = '62b0dd87-eefa-40bf-81d6-cf9bc82692ab' # This environment is created for integration testing
collection_id = None
collection_name = 'FOR-PYTHON-DELETE-ME'

@classmethod
def setup_class(cls):
cls.discovery = ibm_watson.DiscoveryV1(version='2018-08-01')
cls.discovery.set_default_headers({
'X-Watson-Learning-Opt-Out': '1',
'X-Watson-Test': '1'
})
self.environment_id = 'e15f6424-f887-4f50-b4ea-68267c36fc9c' # This environment is created for integration testing
collections = self.discovery.list_collections(self.environment_id).get_result()['collections']
self.collection_id = collections[0]['collection_id']

collections = cls.discovery.list_collections(cls.environment_id).get_result()['collections']
for collection in collections:
if collection['name'] == 'DO-NOT-DELETE-JAPANESE-COLLECTION':
self.collection_id_JP = collection['collection_id']

def tearDown(self):
collections = self.discovery.list_collections(self.environment_id).get_result()['collections']
if collection['name'] == cls.collection_name:
cls.collection_id = collection['collection_id']

if cls.collection_id is None:
print("Creating a new temporary collection")
cls.collection_id = cls.discovery.create_collection(
cls.environment_id,
cls.collection_name,
description="Integration test for python sdk").get_result()['collection_id']

@classmethod
def teardown_class(cls):
collections = cls.discovery.list_collections(cls.environment_id).get_result()['collections']
for collection in collections:
if not collection['name'].startswith('DO-NOT-DELETE'):
self.discovery.delete_collection(self.environment_id, collection['collection_id'])
if collection['name'] == cls.collection_name:
print('Deleting the temporary collection')
cls.discovery.delete_collection(cls.environment_id, cls.collection_id)
break

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

def test_collections_and_expansions(self):
name = 'Example collection for python' + random.choice('ABCDEFGHIJKLMNOPQ')
new_collection_id = self.discovery.create_collection(
self.environment_id,
name,
description="Integration test for python sdk").get_result()['collection_id']
assert new_collection_id is not None

self.discovery.get_collection(self.environment_id, new_collection_id)
self.discovery.get_collection(self.environment_id, self.collection_id)
updated_collection = self.discovery.update_collection(
self.environment_id, new_collection_id, name, description='Updating description').get_result()
self.environment_id, self.collection_id, self.collection_name, description='Updating description').get_result()
assert updated_collection['description'] == 'Updating description'

self.discovery.create_expansions(self.environment_id,
new_collection_id, [{
self.collection_id, [{
'input_terms': ['a'],
'expanded_terms': ['aa']
}]).get_result()
expansions = self.discovery.list_expansions(self.environment_id,
new_collection_id).get_result()
self.collection_id).get_result()
assert expansions['expansions']
self.discovery.delete_expansions(self.environment_id,
new_collection_id)

deleted_collection = self.discovery.delete_collection(
self.environment_id, new_collection_id).get_result()
assert deleted_collection['status'] == 'deleted'
self.collection_id)

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

@pytest.mark.skip(reason="Temporary disable")
def test_tokenization_dictionary(self):
result = self.discovery.get_tokenization_dictionary_status(
self.environment_id,
self.collection_id_JP
self.collection_id
).get_result()
assert result['status'] is not None

Expand Down
13 changes: 5 additions & 8 deletions test/integration/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from os.path import join, dirname
from glob import glob

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

# examples path. /examples
examples_path = join(dirname(__file__), '../', 'examples', '*.py')
examples_path = join(dirname(__file__), '../../', 'examples', '*.py')

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

# exclude some tests cases like authorization
if name in excludes:
if name not in includes:
continue

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

if service_name not in vcap_services:
print('%s does not have credentials in VCAP_SERVICES',
Expand Down
3 changes: 2 additions & 1 deletion test/integration/test_visual_recognition_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ def test_03_analyze(self):
dog_path = os.path.join(os.path.dirname(__file__), '../../resources/dog.jpg')
giraffe_path = os.path.join(os.path.dirname(__file__),
'../../resources/my-giraffe.jpeg')

with open(dog_path, 'rb') as dog_file, open(giraffe_path, 'rb') as giraffe_files:
analyze_images = self.visual_recognition.analyze(
collection_ids=['d31d6534-3458-40c4-b6de-2185a5f3cbe4'],
collection_ids=['684777e5-1f2d-40e3-987f-72d36557ef46'],
features=[AnalyzeEnums.Features.OBJECTS.value],
images_file=[
FileWithMetadata(dog_file),
Expand Down