Skip to content

Commit d062c2e

Browse files
author
Jon Wayne Parrott
committed
Remove grpc-python3 hackiness
Change-Id: I6bf9a8acb9ba7d067b3095b5857094cbc322ff58
1 parent 43b1489 commit d062c2e

File tree

8 files changed

+43
-102
lines changed

8 files changed

+43
-102
lines changed

bigtable/hello/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def main(project_id, instance_id, table_id):
7070
row = table.row(row_key)
7171
row.set_cell(
7272
column_family_id,
73-
column_id.encode('utf-8'),
73+
column_id,
7474
value.encode('utf-8'))
7575
row.commit()
7676
# [END writing_rows]
@@ -79,7 +79,7 @@ def main(project_id, instance_id, table_id):
7979
print('Getting a single greeting by row key.')
8080
key = 'greeting0'
8181
row = table.read_row(key.encode('utf-8'))
82-
value = row.cells[column_family_id][column_id.encode('utf-8')][0].value
82+
value = row.cells[column_family_id][column_id][0].value
8383
print('\t{}: {}'.format(key, value.decode('utf-8')))
8484
# [END getting_a_row]
8585

@@ -90,7 +90,7 @@ def main(project_id, instance_id, table_id):
9090

9191
for row_key, row in partial_rows.rows.items():
9292
key = row_key.decode('utf-8')
93-
cell = row.cells[column_family_id][column_id.encode('utf-8')][0]
93+
cell = row.cells[column_family_id][column_id][0]
9494
value = cell.value.decode('utf-8')
9595
print('\t{}: {}'.format(key, value))
9696
# [END scanning_all_rows]

bigtable/hello/main_test.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,13 @@
1313
# limitations under the License.
1414

1515
import random
16-
import re
17-
import sys
1816

1917
from main import main
2018

21-
import pytest
22-
23-
TABLE_NAME_FORMAT = 'Hello-Bigtable-{}'
19+
TABLE_NAME_FORMAT = 'hell-bigtable-system-tests-{}'
2420
TABLE_NAME_RANGE = 10000
2521

2622

27-
@pytest.mark.skipif(
28-
sys.version_info >= (3, 0),
29-
reason=("grpc doesn't yet support python3 "
30-
'https://github.com/grpc/grpc/issues/282'))
3123
def test_main(cloud_config, capsys):
3224
table_name = TABLE_NAME_FORMAT.format(
3325
random.randrange(TABLE_NAME_RANGE))
@@ -37,12 +29,10 @@ def test_main(cloud_config, capsys):
3729
table_name)
3830

3931
out, _ = capsys.readouterr()
40-
assert re.search(
41-
re.compile(r'Creating the Hello-Bigtable-[0-9]+ table\.'), out)
42-
assert re.search(re.compile(r'Writing some greetings to the table\.'), out)
43-
assert re.search(re.compile(r'Getting a single greeting by row key.'), out)
44-
assert re.search(re.compile(r'greeting0: Hello World!'), out)
45-
assert re.search(re.compile(r'Scanning for all greetings'), out)
46-
assert re.search(re.compile(r'greeting1: Hello Cloud Bigtable!'), out)
47-
assert re.search(
48-
re.compile(r'Deleting the Hello-Bigtable-[0-9]+ table\.'), out)
32+
assert 'Creating the {} table.'.format(table_name) in out
33+
assert 'Writing some greetings to the table.' in out
34+
assert 'Getting a single greeting by row key.' in out
35+
assert 'Hello World!' in out
36+
assert 'Scanning for all greetings' in out
37+
assert 'Hello Cloud Bigtable!' in out
38+
assert 'Deleting the {} table.'.format(table_name) in out

bigtable/hello_happybase/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ def main(project_id, instance_id, table_name):
7777

7878
# [START getting_a_row]
7979
print('Getting a single greeting by row key.')
80-
key = 'greeting0'
80+
key = 'greeting0'.encode('utf-8')
8181
row = table.row(key)
82-
print('\t{}: {}'.format(key, row[column_name]))
82+
print('\t{}: {}'.format(key, row[column_name.encode('utf-8')]))
8383
# [END getting_a_row]
8484

8585
# [START scanning_all_rows]
8686
print('Scanning for all greetings:')
8787

8888
for key, row in table.scan():
89-
print('\t{}: {}'.format(key, row[column_name]))
89+
print('\t{}: {}'.format(key, row[column_name.encode('utf-8')]))
9090
# [END scanning_all_rows]
9191

9292
# [START deleting_a_table]

bigtable/hello_happybase/main_test.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,13 @@
1313
# limitations under the License.
1414

1515
import random
16-
import re
17-
import sys
1816

1917
from main import main
2018

21-
import pytest
22-
23-
TABLE_NAME_FORMAT = 'Hello-Bigtable-{}'
19+
TABLE_NAME_FORMAT = 'hello_happybase-system-tests-{}'
2420
TABLE_NAME_RANGE = 10000
2521

2622

27-
@pytest.mark.skipif(
28-
sys.version_info >= (3, 0),
29-
reason=("grpc doesn't yet support python3 "
30-
'https://github.com/grpc/grpc/issues/282'))
3123
def test_main(cloud_config, capsys):
3224
table_name = TABLE_NAME_FORMAT.format(
3325
random.randrange(TABLE_NAME_RANGE))
@@ -37,12 +29,10 @@ def test_main(cloud_config, capsys):
3729
table_name)
3830

3931
out, _ = capsys.readouterr()
40-
assert re.search(
41-
re.compile(r'Creating the Hello-Bigtable-[0-9]+ table\.'), out)
42-
assert re.search(re.compile(r'Writing some greetings to the table\.'), out)
43-
assert re.search(re.compile(r'Getting a single greeting by row key.'), out)
44-
assert re.search(re.compile(r'greeting0: Hello World!'), out)
45-
assert re.search(re.compile(r'Scanning for all greetings'), out)
46-
assert re.search(re.compile(r'greeting1: Hello Cloud Bigtable!'), out)
47-
assert re.search(
48-
re.compile(r'Deleting the Hello-Bigtable-[0-9]+ table\.'), out)
32+
assert 'Creating the {} table.'.format(table_name) in out
33+
assert 'Writing some greetings to the table.' in out
34+
assert 'Getting a single greeting by row key.' in out
35+
assert 'Hello World!' in out
36+
assert 'Scanning for all greetings' in out
37+
assert 'Hello Cloud Bigtable!' in out
38+
assert 'Deleting the {} table.'.format(table_name) in out

nox.py

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"""
3131

3232
import fnmatch
33-
import itertools
3433
import os
3534
import subprocess
3635
import tempfile
@@ -46,16 +45,6 @@
4645
'-x', '--no-success-flaky-report', '--cov', '--cov-config',
4746
'.coveragerc', '--cov-append', '--cov-report=']
4847

49-
# Blacklists of samples to ingnore.
50-
# Bigtable and Speech are disabled because they use gRPC, which does not yet
51-
# support Python 3. See: https://github.com/grpc/grpc/issues/282
52-
TESTS_BLACKLIST = set((
53-
'./appengine/standard',
54-
'./bigtable',
55-
'./speech',
56-
'./testing'))
57-
APPENGINE_BLACKLIST = set()
58-
5948

6049
# Libraries that only work on Python 2.7
6150
PY27_ONLY_LIBRARIES = ['mysql-python']
@@ -143,8 +132,8 @@ def setup_appengine(session):
143132

144133

145134
def run_tests_in_sesssion(
146-
session, interpreter, use_appengine=False, skip_flaky=False,
147-
changed_only=False, sample_directories=None):
135+
session, interpreter, sample_directories, use_appengine=False,
136+
skip_flaky=False, changed_only=False):
148137
"""This is the main function for executing tests.
149138
150139
It:
@@ -173,13 +162,6 @@ def run_tests_in_sesssion(
173162
if skip_flaky:
174163
pytest_args.append('-m not slow and not flaky')
175164

176-
# session.posargs is any leftover arguments from the command line,
177-
# which allows users to run a particular test instead of all of them.
178-
if session.posargs:
179-
sample_directories = session.posargs
180-
elif sample_directories is None:
181-
sample_directories = collect_sample_dirs('.', TESTS_BLACKLIST)
182-
183165
if changed_only:
184166
changed_files = get_changed_files()
185167
sample_directories = filter_samples(
@@ -204,43 +186,39 @@ def run_tests_in_sesssion(
204186

205187
@nox.parametrize('interpreter', ['python2.7', 'python3.4'])
206188
def session_tests(session, interpreter):
207-
"""Runs tests"""
208-
run_tests_in_sesssion(session, interpreter)
189+
"""Runs tests for all non-gae standard samples."""
190+
# session.posargs is any leftover arguments from the command line,
191+
# which allows users to run a particular test instead of all of them.
192+
if session.posargs:
193+
sample_directories = session.posargs
194+
elif sample_directories is None:
195+
sample_directories = collect_sample_dirs(
196+
'.', set('./appengine/standard'))
197+
198+
run_tests_in_sesssion(session, interpreter, sample_directories)
209199

210200

211201
def session_gae(session):
212202
"""Runs test for GAE Standard samples."""
203+
sample_directories = collect_sample_dirs('appengine/standard')
213204
run_tests_in_sesssion(
214-
session, 'python2.7', use_appengine=True,
215-
sample_directories=collect_sample_dirs(
216-
'appengine/standard',
217-
APPENGINE_BLACKLIST))
218-
219-
220-
def session_grpc(session):
221-
"""Runs tests for samples that need grpc."""
222-
# TODO: Remove this when grpc supports Python 3.
223-
run_tests_in_sesssion(
224-
session,
225-
'python2.7',
226-
sample_directories=itertools.chain(
227-
collect_sample_dirs('speech'),
228-
collect_sample_dirs('bigtable')))
205+
session, 'python2.7', sample_directories, use_appengine=True)
229206

230207

231208
@nox.parametrize('subsession', ['gae', 'tests'])
232209
def session_travis(session, subsession):
233210
"""On travis, just run with python3.4 and don't run slow or flaky tests."""
234211
if subsession == 'tests':
212+
sample_directories = collect_sample_dirs(
213+
'.', set('./appengine/standard'))
235214
run_tests_in_sesssion(
236-
session, 'python3.4', skip_flaky=True, changed_only=True)
215+
session, 'python3.4', sample_directories, skip_flaky=True,
216+
changed_only=True)
237217
else:
218+
sample_directories = collect_sample_dirs('appengine/standard')
238219
run_tests_in_sesssion(
239-
session, 'python2.7', use_appengine=True, skip_flaky=True,
240-
changed_only=True,
241-
sample_directories=collect_sample_dirs(
242-
'appengine/standard',
243-
APPENGINE_BLACKLIST))
220+
session, 'python2.7', sample_directories, use_appengine=True,
221+
skip_flaky=True, changed_only=True)
244222

245223

246224
def session_lint(session):

speech/api/speech_async_grpc_test.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@
1313

1414
import argparse
1515
import re
16-
import sys
1716

1817
import pytest
1918
from speech_async_grpc import _gcs_uri
2019
from speech_async_grpc import main
2120

2221

23-
@pytest.mark.skipif(
24-
sys.version_info >= (3, 0),
25-
reason=("grpc doesn't yet support python3 "
26-
'https://github.com/grpc/grpc/issues/282'))
2722
def test_main(cloud_config, capsys):
2823
input_uri = 'gs://{}/speech/audio.flac'.format(cloud_config.storage_bucket)
2924

speech/api/speech_grpc_test.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,12 @@
1212
# limitations under the License.
1313

1414
import re
15-
import sys
1615

1716
import pytest
1817
from speech_grpc import _gcs_uri
1918
from speech_grpc import main
2019

2120

22-
@pytest.mark.skipif(
23-
sys.version_info >= (3, 0),
24-
reason=("grpc doesn't yet support python3 "
25-
'https://github.com/grpc/grpc/issues/282'))
2621
def test_main(cloud_config, capsys):
2722
input_uri = 'gs://{}/speech/audio.flac'.format(cloud_config.storage_bucket)
2823

speech/api/speech_streaming_test.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414
import contextlib
1515
import io
1616
import re
17-
import sys
1817
import time
1918

20-
import pytest
21-
2219
import speech_streaming
2320

2421

@@ -57,10 +54,6 @@ def mock_audio_stream(channels, rate, chunk):
5754
return mock_audio_stream
5855

5956

60-
@pytest.mark.skipif(
61-
sys.version_info >= (3, 0),
62-
reason=("grpc doesn't yet support python3 "
63-
'https://github.com/grpc/grpc/issues/282'))
6457
def test_main(resource, monkeypatch, capsys):
6558
monkeypatch.setattr(
6659
speech_streaming, 'record_audio',

0 commit comments

Comments
 (0)