1616
1717See the :doc: `api-reference ` for full usage details.
1818
19- .. code :: python
19+ .. testsetup :: simple
20+
21+ import pathlib
22+ import shutil
23+
24+ import vws_test_fixtures
25+ from mock_vws import MockVWS
26+ from mock_vws.database import VuforiaDatabase
27+
28+ mock = MockVWS(real_http=False)
29+ database = VuforiaDatabase(
30+ server_access_key='[server-access-key]',
31+ server_secret_key='[server-secret-key]',
32+ client_access_key='[client-access-key]',
33+ client_secret_key='[client-secret-key]',
34+ )
35+ mock.add_database(database=database)
36+ mock.__enter__()
37+
38+ # We rely on implementation details of the fixtures package.
39+ image = pathlib.Path(vws_test_fixtures.__path__[0]) / 'high_quality_image.jpg'
40+ assert image.exists(), image.resolve()
41+ new_image = pathlib.Path('high_quality_image.jpg')
42+ shutil.copy(image, new_image)
43+
44+ .. testcode :: simple
2045
2146 import io
47+ import pathlib
2248
2349 from vws import VWS, CloudRecoService
2450
@@ -37,7 +63,8 @@ See the :doc:`api-reference` for full usage details.
3763 )
3864 name = 'my_image_name'
3965
40- with open (' /path/to/image.png' , ' rb' ) as my_image_file:
66+ image = pathlib.Path('high_quality_image.jpg')
67+ with image.open(mode='rb') as my_image_file:
4168 my_image = io.BytesIO(my_image_file.read())
4269
4370 target_id = vws_client.add_target(
@@ -52,6 +79,12 @@ See the :doc:`api-reference` for full usage details.
5279
5380 assert matching_targets[0].target_id == target_id
5481
82+ .. testcleanup :: simple
83+
84+ new_image = pathlib.Path('high_quality_image.jpg')
85+ new_image.unlink()
86+ mock.__exit__()
87+
5588Testing
5689-------
5790
@@ -61,7 +94,7 @@ To write unit tests for code which uses this library, without using your Vuforia
6194
6295 pip3 install vws-python-mock
6396
64- .. testsetup ::
97+ .. testsetup :: testing
6598
6699 import pathlib
67100 import shutil
@@ -74,7 +107,7 @@ To write unit tests for code which uses this library, without using your Vuforia
74107 new_image = pathlib.Path('high_quality_image.jpg')
75108 shutil.copy(image, new_image)
76109
77- .. testcode ::
110+ .. testcode :: testing
78111
79112 import io
80113 import pathlib
@@ -108,7 +141,7 @@ To write unit tests for code which uses this library, without using your Vuforia
108141 active_flag=True,
109142 )
110143
111- .. testcleanup ::
144+ .. testcleanup :: testing
112145
113146 new_image = pathlib.Path('high_quality_image.jpg')
114147 new_image.unlink()
0 commit comments