Skip to content

Commit a156be4

Browse files
author
Jon Wayne Parrott
authored
Remove resource (#890)
* Remove resource fixture * Remove remote resource
1 parent bc911ec commit a156be4

23 files changed

+112
-103
lines changed

appengine/standard/bigquery/main_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import main
2424

25+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
2526
PROJECT = os.environ['GCLOUD_PROJECT']
2627

2728

@@ -49,11 +50,11 @@ def test_loggedin(app, login):
4950
assert re.search(r'.*oauth2.*', response.headers['Location'])
5051

5152

52-
def test_oauthed(resource, app, login):
53+
def test_oauthed(app, login):
5354
login()
5455

5556
mock_http = HttpMock(
56-
resource('datasets-list.json'),
57+
os.path.join(RESOURCES, 'datasets-list.json'),
5758
{'status': '200'})
5859

5960
with mock.patch.object(main.decorator, 'http', return_value=mock_http):

bigquery/api/load_data_by_post_test.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818

1919
from load_data_by_post import load_data
2020

21+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
2122
PROJECT = os.environ['GCLOUD_PROJECT']
2223
DATASET_ID = 'ephemeral_test_dataset'
2324
TABLE_ID = 'load_data_by_post'
2425

2526

2627
@flaky
27-
def test_load_csv_data(resource, capsys):
28-
schema_path = resource('schema.json')
29-
data_path = resource('data.csv')
28+
def test_load_csv_data(capsys):
29+
schema_path = os.path.join(RESOURCES, 'schema.json')
30+
data_path = os.path.join(RESOURCES, 'data.csv')
3031

3132
load_data(
3233
schema_path,
@@ -43,9 +44,9 @@ def test_load_csv_data(resource, capsys):
4344

4445

4546
@flaky
46-
def test_load_json_data(resource, capsys):
47-
schema_path = resource('schema.json')
48-
data_path = resource('data.json')
47+
def test_load_json_data(capsys):
48+
schema_path = os.path.join(RESOURCES, 'schema.json')
49+
data_path = os.path.join(RESOURCES, 'data.json')
4950

5051
load_data(
5152
schema_path,

bigquery/api/load_data_from_csv_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717

1818
from load_data_from_csv import main
1919

20+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
2021
PROJECT = os.environ['GCLOUD_PROJECT']
2122
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
2223
DATASET_ID = 'test_dataset'
2324
TABLE_ID = 'test_import_table'
2425

2526

2627
@flaky
27-
def test_load_table(resource):
28+
def test_load_table():
2829
cloud_storage_input_uri = 'gs://{}/data.csv'.format(BUCKET)
29-
schema_file = resource('schema.json')
30+
schema_file = os.path.join(RESOURCES, 'schema.json')
3031

3132
main(
3233
PROJECT,

bigquery/api/streaming_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616

1717
import streaming
1818

19+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
1920
PROJECT = os.environ['GCLOUD_PROJECT']
2021
DATASET_ID = 'test_dataset'
2122
TABLE_ID = 'test_table'
2223

2324

24-
def test_stream_row_to_bigquery(resource, capsys):
25-
with open(resource('streamrows.json'), 'r') as rows_file:
25+
def test_stream_row_to_bigquery(capsys):
26+
with open(os.path.join(RESOURCES, 'streamrows.json'), 'r') as rows_file:
2627
rows = json.load(rows_file)
2728

2829
streaming.get_rows = lambda: rows

bigquery/cloud-client/load_data_from_file_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
import os
15+
1416
import load_data_from_file
1517

18+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
1619
DATASET_ID = 'test_dataset'
1720
TABLE_ID = 'test_import_table'
1821

1922

20-
def test_load_table(resource, capsys):
21-
data_path = resource('data.csv')
23+
def test_load_table(capsys):
24+
data_path = os.path.join(RESOURCES, 'data.csv')
2225

2326
load_data_from_file.load_data_from_file(
2427
DATASET_ID,

conftest.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,8 @@
1616

1717
import mock
1818
import pytest
19-
import requests
2019

2120
PROJECT = os.environ['GCLOUD_PROJECT']
22-
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
23-
24-
25-
def get_resource_path(resource, local_path):
26-
local_resource_path = os.path.join(local_path, 'resources', *resource)
27-
28-
if os.path.exists(local_resource_path):
29-
return local_resource_path
30-
else:
31-
raise EnvironmentError('Resource {} not found.'.format(
32-
os.path.join(*resource)))
33-
34-
35-
@pytest.fixture(scope='module')
36-
def resource(request):
37-
"""Provides a function that returns the full path to a local or global
38-
testing resource"""
39-
local_path = os.path.dirname(request.module.__file__)
40-
return lambda *args: get_resource_path(args, local_path)
41-
42-
43-
def fetch_gcs_resource(resource, tmpdir, _chunk_size=1024):
44-
resp = requests.get(resource, stream=True)
45-
dest_file = str(tmpdir.join(os.path.basename(resource)))
46-
with open(dest_file, 'wb') as f:
47-
for chunk in resp.iter_content(_chunk_size):
48-
f.write(chunk)
49-
50-
return dest_file
51-
52-
53-
@pytest.fixture(scope='module')
54-
def remote_resource():
55-
"""Provides a function that downloads the given resource from Cloud
56-
Storage, returning the path to the downloaded resource."""
57-
remote_uri = 'http://storage.googleapis.com/{}/'.format(
58-
BUCKET)
59-
60-
return lambda path, tmpdir: fetch_gcs_resource(
61-
remote_uri + path.strip('/'), tmpdir)
6221

6322

6423
@pytest.fixture

language/ocr_nl/main_test.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
import re
1818
import zipfile
1919

20+
import requests
21+
2022
import main
2123

2224
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
2325
TEST_IMAGE_URI = 'gs://{}/language/image8.png'.format(BUCKET)
26+
OCR_IMAGES_URI = 'http://storage.googleapis.com/{}/{}'.format(
27+
BUCKET, 'language/ocr_nl-images-small.zip')
2428

2529

2630
def test_batch_empty():
@@ -79,14 +83,16 @@ def test_entities_list():
7983
assert wurl == 'http://en.wikipedia.org/wiki/Mr_Bennet'
8084

8185

82-
def test_main(remote_resource, tmpdir, capsys):
86+
def test_main(tmpdir, capsys):
8387
images_path = str(tmpdir.mkdir('images'))
8488

8589
# First, pull down some test data
86-
zip_path = remote_resource('language/ocr_nl-images-small.zip', tmpdir)
90+
response = requests.get(OCR_IMAGES_URI)
91+
images_file = tmpdir.join('images.zip')
92+
images_file.write_binary(response.content)
8793

8894
# Extract it to the image directory
89-
with zipfile.ZipFile(zip_path) as zfile:
95+
with zipfile.ZipFile(str(images_file)) as zfile:
9096
zfile.extractall(images_path)
9197

9298
main.main(images_path, str(tmpdir.join('ocr_nl.db')))

language/sentiment/sentiment_analysis_test.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,40 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
import os
1415
import re
1516

1617
from sentiment_analysis import analyze
1718

19+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
1820

19-
def test_pos(resource, capsys):
20-
analyze(resource('pos.txt'))
21+
22+
def test_pos(capsys):
23+
analyze(os.path.join(RESOURCES, 'pos.txt'))
2124
out, err = capsys.readouterr()
2225
score = float(re.search('score of (.+?) with', out).group(1))
2326
magnitude = float(re.search('magnitude of (.+?)', out).group(1))
2427
assert score * magnitude > 0
2528

2629

27-
def test_neg(resource, capsys):
28-
analyze(resource('neg.txt'))
30+
def test_neg(capsys):
31+
analyze(os.path.join(RESOURCES, 'neg.txt'))
2932
out, err = capsys.readouterr()
3033
score = float(re.search('score of (.+?) with', out).group(1))
3134
magnitude = float(re.search('magnitude of (.+?)', out).group(1))
3235
assert score * magnitude < 0
3336

3437

35-
def test_mixed(resource, capsys):
36-
analyze(resource('mixed.txt'))
38+
def test_mixed(capsys):
39+
analyze(os.path.join(RESOURCES, 'mixed.txt'))
3740
out, err = capsys.readouterr()
3841
score = float(re.search('score of (.+?) with', out).group(1))
3942
assert score <= 0.3
4043
assert score >= -0.3
4144

4245

43-
def test_neutral(resource, capsys):
44-
analyze(resource('neutral.txt'))
46+
def test_neutral(capsys):
47+
analyze(os.path.join(RESOURCES, 'neutral.txt'))
4548
out, err = capsys.readouterr()
4649
magnitude = float(re.search('magnitude of (.+?)', out).group(1))
4750
assert magnitude <= 2.0

language/syntax_triples/main_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
1516
import re
1617

1718
import main
1819

20+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
21+
1922

2023
def test_dependents():
2124
text = "I am eating a delicious banana"
@@ -41,8 +44,8 @@ def test_find_triples():
4144
assert (1, 2, 5) == triple
4245

4346

44-
def test_obama_example(resource, capsys):
45-
main.main(resource('obama_wikipedia.txt'))
47+
def test_obama_example(capsys):
48+
main.main(os.path.join(RESOURCES, 'obama_wikipedia.txt'))
4649
stdout, _ = capsys.readouterr()
4750
lines = stdout.split('\n')
4851
assert re.match(

monitoring/api/v3/cloud-client/snippets_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_list_resources(capsys):
3737
assert 'pubsub_topic' in out
3838

3939

40-
def test_get_resource(capsys):
40+
def test_get_resources(capsys):
4141
snippets.get_monitored_resource_descriptor('pubsub_topic')
4242
out, _ = capsys.readouterr()
4343
assert 'A topic in Google Cloud Pub/Sub' in out

speech/api-client/transcribe_async_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
import os
1415
import re
1516

1617
from transcribe_async import main
1718

19+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
1820

19-
def test_main(resource, capsys):
20-
main(resource('audio.raw'))
21+
22+
def test_main(capsys):
23+
main(os.path.join(RESOURCES, 'audio.raw'))
2124
out, err = capsys.readouterr()
2225

2326
assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I)

speech/api-client/transcribe_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
import os
1415
import re
1516

1617
from transcribe import main
1718

19+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
1820

19-
def test_main(resource, capsys):
20-
main(resource('audio.raw'))
21+
22+
def test_main(capsys):
23+
main(os.path.join(RESOURCES, 'audio.raw'))
2124
out, err = capsys.readouterr()
2225

2326
assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I)

speech/cloud-client/transcribe_async_test.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
import os
1415
import re
1516

1617
import transcribe_async
1718

19+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
1820

19-
def test_transcribe(resource, capsys):
20-
transcribe_async.transcribe_file(resource('audio.raw'))
21+
22+
def test_transcribe(capsys):
23+
transcribe_async.transcribe_file(
24+
os.path.join(RESOURCES, 'audio.raw'))
2125
out, err = capsys.readouterr()
2226

2327
assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I)
2428

2529

26-
def test_transcribe_gcs(resource, capsys):
30+
def test_transcribe_gcs(capsys):
2731
transcribe_async.transcribe_gcs(
2832
'gs://python-docs-samples-tests/speech/audio.flac')
2933
out, err = capsys.readouterr()

speech/cloud-client/transcribe_streaming_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
import os
1415
import re
1516

1617
import transcribe_streaming
1718

19+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
1820

19-
def test_transcribe_streaming(resource, capsys):
20-
transcribe_streaming.transcribe_streaming(resource('audio.raw'))
21+
22+
def test_transcribe_streaming(capsys):
23+
transcribe_streaming.transcribe_streaming(
24+
os.path.join(RESOURCES, 'audio.raw'))
2125
out, err = capsys.readouterr()
2226

2327
assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I)

speech/cloud-client/transcribe_test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,22 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
import os
1415
import re
1516

1617
import transcribe
1718

19+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
1820

19-
def test_transcribe_file(resource, capsys):
20-
transcribe.transcribe_file(resource('audio.raw'))
21+
22+
def test_transcribe_file(capsys):
23+
transcribe.transcribe_file(os.path.join(RESOURCES, 'audio.raw'))
2124
out, err = capsys.readouterr()
2225

2326
assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I)
2427

2528

26-
def test_transcribe_gcs(resource, capsys):
29+
def test_transcribe_gcs(capsys):
2730
transcribe.transcribe_gcs(
2831
'gs://python-docs-samples-tests/speech/audio.flac')
2932
out, err = capsys.readouterr()

0 commit comments

Comments
 (0)