X Tutup
Skip to content

Commit fe4b308

Browse files
Merge branch 'develop' into codegen/vr
2 parents 48c80e4 + 2301d5c commit fe4b308

14 files changed

+3192
-1433
lines changed

examples/tone_analyzer_v3.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,13 @@
4343
tone = tone_analyzer.tone(json.load(tone_html)['text'],
4444
content_type='text/html')
4545
print(json.dumps(tone, indent=2))
46+
47+
print("\ntone() example 6 with GDPR support:\n")
48+
tone_analyzer.set_detailed_response(True)
49+
with open(join(dirname(__file__),
50+
'../resources/tone-example-html.json')) as tone_html:
51+
tone = tone_analyzer.tone(json.load(tone_html)['text'],
52+
content_type='text/html',
53+
headers={'Custom-Header': 'custom_value'})
54+
55+
print(tone)

test/integration/test_discovery_v1.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@
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 = watson_developer_cloud.DiscoveryV1(
11+
discovery = None
12+
environment_id = 'e15f6424-f887-4f50-b4ea-68267c36fc9c' # This environment is created for integration testing
13+
collection_id = None
14+
15+
@classmethod
16+
def setup_class(cls):
17+
cls.discovery = watson_developer_cloud.DiscoveryV1(
1318
version='2017-10-16',
1419
username="YOUR SERVICE USERNAME",
1520
password="YOUR SERVICE PASSWORD")
16-
self.discovery.set_default_headers({
21+
cls.discovery.set_default_headers({
1722
'X-Watson-Learning-Opt-Out': '1',
1823
'X-Watson-Test': '1'
1924
})
20-
self.environment_id = 'e15f6424-f887-4f50-b4ea-68267c36fc9c' # This environment is created for integration testing
21-
self.collection_id = self.discovery.list_collections(
22-
self.environment_id)['collections'][0]['collection_id']
25+
cls.collection_id = cls.discovery.list_collections(cls.environment_id)['collections'][0]['collection_id']
26+
27+
@classmethod
28+
def teardown_class(cls):
29+
collections = cls.discovery.list_collections(cls.environment_id)['collections']
30+
for collection in collections:
31+
if collection['name'] != 'DO-NOT-DELETE':
32+
cls.discovery.delete_collection(cls.environment_id, collection['collection_id'])
2333

2434
def test_environments(self):
2535
envs = self.discovery.list_environments()
@@ -86,10 +96,7 @@ def test_documents(self):
8696
self.environment_id, self.collection_id, add_doc['document_id'])
8797
assert doc_status is not None
8898

89-
with open(
90-
os.path.join(
91-
os.path.dirname(__file__), '../../resources/simple.html'),
92-
'r') as fileinfo:
99+
with open(os.path.join(os.path.dirname(__file__), '../../resources/simple.html'), 'r') as fileinfo:
93100
update_doc = self.discovery.update_document(
94101
self.environment_id,
95102
self.collection_id,

test/integration/test_speech_to_text_v1.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,32 @@
88
@pytest.mark.skipif(
99
os.getenv('VCAP_SERVICES') is None, reason='requires VCAP_SERVICES')
1010
class TestSpeechToTextV1(TestCase):
11-
def setUp(self):
12-
self.speech_to_text = watson_developer_cloud.SpeechToTextV1(
11+
text_to_speech = None
12+
custom_models = None
13+
create_custom_model = None
14+
customization_id = None
15+
16+
@classmethod
17+
def setup_class(cls):
18+
cls.speech_to_text = watson_developer_cloud.SpeechToTextV1(
1319
username=os.getenv('YOUR SERVICE USERNAME'),
1420
password=os.getenv('YOUR SERVICE PASSWORD'))
15-
self.speech_to_text.set_default_headers({
21+
cls.speech_to_text.set_default_headers({
1622
'X-Watson-Learning-Opt-Out':
1723
'1',
1824
'X-Watson-Test':
1925
'1'
2026
})
21-
self.custom_models = self.speech_to_text.list_language_models()
22-
self.create_custom_model = self.speech_to_text.create_language_model(
27+
cls.custom_models = cls.speech_to_text.list_language_models()
28+
cls.create_custom_model = cls.speech_to_text.create_language_model(
2329
name="integration_test_model",
2430
base_model_name="en-US_BroadbandModel")
25-
self.customization_id = self.create_custom_model['customization_id']
31+
cls.customization_id = cls.create_custom_model['customization_id']
2632

27-
def tearDown(self):
28-
self.speech_to_text.delete_language_model(
29-
customization_id=self.create_custom_model['customization_id'])
33+
@classmethod
34+
def teardown_class(cls):
35+
cls.speech_to_text.delete_language_model(
36+
customization_id=cls.create_custom_model['customization_id'])
3037

3138
def test_models(self):
3239
output = self.speech_to_text.list_models()

test/integration/test_text_to_speech_v1.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,29 @@
77
@pytest.mark.skipif(
88
os.getenv('VCAP_SERVICES') is None, reason='requires VCAP_SERVICES')
99
class TestIntegrationTextToSpeechV1(unittest.TestCase):
10-
def setUp(self):
11-
self.text_to_speech = watson_developer_cloud.TextToSpeechV1(
10+
text_to_speech = None
11+
original_customizations = None
12+
created_customization = None
13+
14+
@classmethod
15+
def setup_class(cls):
16+
cls.text_to_speech = watson_developer_cloud.TextToSpeechV1(
1217
username="YOUR SERVICE USERNAME", password="YOUR SERVICE PASSWORD")
13-
self.text_to_speech.set_default_headers({
18+
cls.text_to_speech.set_default_headers({
1419
'X-Watson-Learning-Opt-Out':
1520
'1',
1621
'X-Watson-Test':
1722
'1'
1823
})
19-
self.original_customizations = self.text_to_speech.list_voice_models()
20-
self.created_customization = self.text_to_speech.create_voice_model(
24+
cls.original_customizations = cls.text_to_speech.list_voice_models()
25+
cls.created_customization = cls.text_to_speech.create_voice_model(
2126
name="test_integration_customization",
2227
description="customization for tests")
2328

24-
def tearDown(self):
25-
custid = self.created_customization['customization_id']
26-
self.text_to_speech.delete_voice_model(customization_id=custid)
29+
@classmethod
30+
def teardown_class(cls):
31+
custid = cls.created_customization['customization_id']
32+
cls.text_to_speech.delete_voice_model(customization_id=custid)
2733

2834
def test_voices(self):
2935
output = self.text_to_speech.list_voices()

0 commit comments

Comments
 (0)
X Tutup