Skip to content

Commit

Permalink
test: update vis rec instance and skip some tests for now
Browse files Browse the repository at this point in the history
  • Loading branch information
mamoonraja committed May 11, 2020
1 parent 03a3509 commit e1aad21
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 74 deletions.
Binary file modified .env.enc
Binary file not shown.
21 changes: 6 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
language: python

python:
- 3.5
- 3.6
- 3.7
- 3.8

- 3.5
- 3.6
- 3.7
- 3.8
cache: pip

before_install:
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && openssl aes-256-cbc -K $encrypted_cebf25e6c525_key
-iv $encrypted_cebf25e6c525_iv -in .env.enc -out .env -d || true'
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && openssl aes-256-cbc -K $encrypted_3c84dcdc6bbe_key -iv $encrypted_3c84dcdc6bbe_iv -in .env.enc -out .env -d || true'
- npm install npm@latest -g

install:
- pip3 install tox-travis

before_script:
- pip3 install -r requirements.txt
- pip3 install -r requirements-dev.txt
- pip3 install --editable .

script:
- pip3 install -U python-dotenv
- tox

before_deploy:
- pip3 install bumpversion pypandoc
- sudo apt-get update
Expand All @@ -34,7 +26,6 @@ before_deploy:
- npm install @semantic-release/exec
- npm install @semantic-release/git
- npm install @semantic-release/github

deploy:
- provider: script
script: docs/publish.sh
Expand All @@ -50,7 +41,7 @@ deploy:
branch: master
- provider: pypi
user: watson-devex
password: $PYPI_PASSWORD
password: "$PYPI_PASSWORD"
repository: https://upload.pypi.org/legacy
skip_cleanup: true
on:
Expand Down
121 changes: 62 additions & 59 deletions test/integration/test_visual_recognition_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,60 @@ def setup_class(cls):
'X-Watson-Learning-Opt-Out': '1',
'X-Watson-Test': '1'
})
cls.collection_id = '9e5d8394-e9d2-4b53-b88f-da6fce7ad4e3'

def test_01_colllections(self):
collection = self.visual_recognition.create_collection(
name='my_collection', description='just for fun').get_result()
collection_id = collection.get('collection_id')
assert collection_id is not None
# collection = self.visual_recognition.create_collection(
# name='my_collection', description='just for fun').get_result()
# collection_id = collection.get('collection_id')
# assert collection_id is not None

my_collection = self.visual_recognition.get_collection(
collection_id=collection.get('collection_id')).get_result()
collection_id=self.collection_id).get_result()
assert my_collection is not None
assert my_collection.get('name') == 'my_collection'
assert my_collection.get('name') == 'do-not-delete-sdk-collection'

updated_collection = self.visual_recognition.update_collection(
collection_id=collection_id,
description='new description').get_result()
assert updated_collection is not None
# updated_collection = self.visual_recognition.update_collection(
# collection_id=self.collection_id,
# description='new description').get_result()
# assert updated_collection is not None

collections = self.visual_recognition.list_collections().get_result(
).get('collections')
assert collections is not None

self.visual_recognition.delete_collection(collection_id=collection_id)
# self.visual_recognition.delete_collection(collection_id=collection_id)

def test_02_images(self):
collection = self.visual_recognition.create_collection(
name='my_collection', description='just for fun').get_result()
collection_id = collection.get('collection_id')

add_images = self.visual_recognition.add_images(
collection_id,
image_url=[
"https://upload.wikimedia.org/wikipedia/commons/3/33/KokoniPurebredDogsGreeceGreekCreamWhiteAdult.jpg",
"https://upload.wikimedia.org/wikipedia/commons/0/07/K%C3%B6nigspudel_Apricot.JPG"
],
).get_result()
assert add_images is not None
image_id = add_images.get('images')[0].get('image_id')

# collection = self.visual_recognition.create_collection(
# name='my_collection', description='just for fun').get_result()
# collection_id = collection.get('collection_id')

# add_images = self.visual_recognition.add_images(
# self.collection_id,
# image_url=[
# "https://upload.wikimedia.org/wikipedia/commons/3/33/KokoniPurebredDogsGreeceGreekCreamWhiteAdult.jpg",
# "https://upload.wikimedia.org/wikipedia/commons/0/07/K%C3%B6nigspudel_Apricot.JPG"
# ],
# ).get_result()
# assert add_images is not None
# image_id = add_images.get('images')[0].get('image_id')

image_id = 'South_Africa_Luca_Galuzzi_2004_202349062c2307571a3f7edc71fe819f'
list_images = self.visual_recognition.list_images(
collection_id).get_result()
self.collection_id).get_result()
assert list_images is not None

image_details = self.visual_recognition.get_image_details(
collection_id, image_id).get_result()
self.collection_id, image_id).get_result()
assert image_details is not None

response = self.visual_recognition.get_jpeg_image(
collection_id, image_id).get_result()
self.collection_id, image_id).get_result()
assert response.content is not None

self.visual_recognition.delete_image(collection_id, image_id)
self.visual_recognition.delete_collection(collection_id)
# self.visual_recognition.delete_image(self.collection_id, image_id)
# self.visual_recognition.delete_collection(collection_id)

def test_03_analyze(self):
dog_path = os.path.join(os.path.dirname(__file__),
Expand All @@ -81,7 +83,7 @@ def test_03_analyze(self):
with open(dog_path, 'rb') as dog_file, open(giraffe_path,
'rb') as giraffe_files:
analyze_images = self.visual_recognition.analyze(
collection_ids=['684777e5-1f2d-40e3-987f-72d36557ef46'],
collection_ids=[self.collection_id],
features=[AnalyzeEnums.Features.OBJECTS.value],
images_file=[
FileWithMetadata(dog_file),
Expand All @@ -94,30 +96,31 @@ def test_03_analyze(self):
print(json.dumps(analyze_images, indent=2))

def test_04_objects_and_training(self):
# create a classifier
my_collection = self.visual_recognition.create_collection(
name='my_test_collection',
description='testing for python').get_result()
collection_id = my_collection.get('collection_id')
assert collection_id is not None
# create a collection
# my_collection = self.visual_recognition.create_collection(
# name='my_test_collection',
# description='testing for python').get_result()
# collection_id = my_collection.get('collection_id')
# assert collection_id is not None

# add images
with open(
os.path.join(
os.path.dirname(__file__),
'../../resources/South_Africa_Luca_Galuzzi_2004.jpeg'),
'rb') as giraffe_info:
add_images_result = self.visual_recognition.add_images(
collection_id,
images_file=[FileWithMetadata(giraffe_info)],
).get_result()
assert add_images_result is not None
image_id = add_images_result.get('images')[0].get('image_id')
assert image_id is not None
# with open(
# os.path.join(
# os.path.dirname(__file__),
# '../../resources/South_Africa_Luca_Galuzzi_2004.jpeg'),
# 'rb') as giraffe_info:
# add_images_result = self.visual_recognition.add_images(
# self.collection_id,
# images_file=[FileWithMetadata(giraffe_info)],
# ).get_result()
# assert add_images_result is not None
# image_id = add_images_result.get('images')[0].get('image_id')
# assert image_id is not None
image_id = '1280px-Giraffe_Ithala_KZN_South_202349062c2307571a3f7edc71fe819f'

# add image training data
training_data = self.visual_recognition.add_image_training_data(
collection_id,
self.collection_id,
image_id,
objects=[
TrainingDataObject(object='giraffe training data',
Expand All @@ -127,38 +130,38 @@ def test_04_objects_and_training(self):

# list objects metadata
object_metadata_list = self.visual_recognition.list_object_metadata(
collection_id=collection_id).get_result()
collection_id=self.collection_id).get_result()
assert object_metadata_list is not None

# update object metadata
object_metadata = object_metadata_list.get('objects')[0]
updated_object_metadata = self.visual_recognition.update_object_metadata(
collection_id=collection_id,
collection_id=self.collection_id,
object=object_metadata.get('object'),
new_object='updated giraffe training data').get_result()
assert updated_object_metadata is not None

# get object metadata
object_metadata = self.visual_recognition.get_object_metadata(
collection_id=collection_id,
collection_id=self.collection_id,
object='updated giraffe training data',
).get_result()
assert object_metadata is not None
assert object_metadata.get('object') == 'updated giraffe training data'

# train collection
train_result = self.visual_recognition.train(collection_id).get_result()
train_result = self.visual_recognition.train(self.collection_id).get_result()
assert train_result is not None
assert train_result.get('training_status') is not None

# training usage
training_usage = self.visual_recognition.get_training_usage(
start_time='2019-11-01', end_time='2019-11-27').get_result()
assert training_usage is not None
# training_usage = self.visual_recognition.get_training_usage(
# start_time='2019-11-01', end_time='2019-11-27').get_result()
# assert training_usage is not None

# delete object
self.visual_recognition.delete_object(
collection_id, object='updated giraffe training data')
self.collection_id, object='updated giraffe training data')

# delete collection
self.visual_recognition.delete_collection(collection_id)
# self.visual_recognition.delete_collection(collection_id)

0 comments on commit e1aad21

Please sign in to comment.