Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup nox #462

Merged
merged 4 commits into from
Aug 18, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bigtable/hello/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def main(project_id, instance_id, table_id):
row = table.row(row_key)
row.set_cell(
column_family_id,
column_id.encode('utf-8'),
column_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have some six magic for python2 compatibility?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Jon is just fixing a double encode? I think in general if you want Python strings as bytes, do the encode, no six necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah cool. I totally didn't look at the context ^_^;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah fixing a double encode. No idea how this worked on py2.7 other than luck.

value.encode('utf-8'))
row.commit()
# [END writing_rows]
Expand All @@ -79,7 +79,7 @@ def main(project_id, instance_id, table_id):
print('Getting a single greeting by row key.')
key = 'greeting0'
row = table.read_row(key.encode('utf-8'))
value = row.cells[column_family_id][column_id.encode('utf-8')][0].value
value = row.cells[column_family_id][column_id][0].value
print('\t{}: {}'.format(key, value.decode('utf-8')))
# [END getting_a_row]

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

for row_key, row in partial_rows.rows.items():
key = row_key.decode('utf-8')
cell = row.cells[column_family_id][column_id.encode('utf-8')][0]
cell = row.cells[column_family_id][column_id][0]
value = cell.value.decode('utf-8')
print('\t{}: {}'.format(key, value))
# [END scanning_all_rows]
Expand Down
26 changes: 8 additions & 18 deletions bigtable/hello/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,13 @@
# limitations under the License.

import random
import re
import sys

from main import main

import pytest

TABLE_NAME_FORMAT = 'Hello-Bigtable-{}'
TABLE_NAME_FORMAT = 'hell-bigtable-system-tests-{}'
TABLE_NAME_RANGE = 10000


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

out, _ = capsys.readouterr()
assert re.search(
re.compile(r'Creating the Hello-Bigtable-[0-9]+ table\.'), out)
assert re.search(re.compile(r'Writing some greetings to the table\.'), out)
assert re.search(re.compile(r'Getting a single greeting by row key.'), out)
assert re.search(re.compile(r'greeting0: Hello World!'), out)
assert re.search(re.compile(r'Scanning for all greetings'), out)
assert re.search(re.compile(r'greeting1: Hello Cloud Bigtable!'), out)
assert re.search(
re.compile(r'Deleting the Hello-Bigtable-[0-9]+ table\.'), out)
assert 'Creating the {} table.'.format(table_name) in out
assert 'Writing some greetings to the table.' in out
assert 'Getting a single greeting by row key.' in out
assert 'Hello World!' in out
assert 'Scanning for all greetings' in out
assert 'Hello Cloud Bigtable!' in out
assert 'Deleting the {} table.'.format(table_name) in out
6 changes: 3 additions & 3 deletions bigtable/hello_happybase/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ def main(project_id, instance_id, table_name):

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

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

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

# [START deleting_a_table]
Expand Down
26 changes: 8 additions & 18 deletions bigtable/hello_happybase/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,13 @@
# limitations under the License.

import random
import re
import sys

from main import main

import pytest

TABLE_NAME_FORMAT = 'Hello-Bigtable-{}'
TABLE_NAME_FORMAT = 'hello_happybase-system-tests-{}'
TABLE_NAME_RANGE = 10000


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

out, _ = capsys.readouterr()
assert re.search(
re.compile(r'Creating the Hello-Bigtable-[0-9]+ table\.'), out)
assert re.search(re.compile(r'Writing some greetings to the table\.'), out)
assert re.search(re.compile(r'Getting a single greeting by row key.'), out)
assert re.search(re.compile(r'greeting0: Hello World!'), out)
assert re.search(re.compile(r'Scanning for all greetings'), out)
assert re.search(re.compile(r'greeting1: Hello Cloud Bigtable!'), out)
assert re.search(
re.compile(r'Deleting the Hello-Bigtable-[0-9]+ table\.'), out)
assert 'Creating the {} table.'.format(table_name) in out
assert 'Writing some greetings to the table.' in out
assert 'Getting a single greeting by row key.' in out
assert 'Hello World!' in out
assert 'Scanning for all greetings' in out
assert 'Hello Cloud Bigtable!' in out
assert 'Deleting the {} table.'.format(table_name) in out
64 changes: 21 additions & 43 deletions nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"""

import fnmatch
import itertools
import os
import subprocess
import tempfile
Expand All @@ -46,16 +45,6 @@
'-x', '--no-success-flaky-report', '--cov', '--cov-config',
'.coveragerc', '--cov-append', '--cov-report=']

# Blacklists of samples to ingnore.
# Bigtable and Speech are disabled because they use gRPC, which does not yet
# support Python 3. See: https://github.com/grpc/grpc/issues/282
TESTS_BLACKLIST = set((
'./appengine/standard',
'./bigtable',
'./speech',
'./testing'))
APPENGINE_BLACKLIST = set()


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


def run_tests_in_sesssion(
session, interpreter, use_appengine=False, skip_flaky=False,
changed_only=False, sample_directories=None):
session, interpreter, sample_directories, use_appengine=False,
skip_flaky=False, changed_only=False):
"""This is the main function for executing tests.

It:
Expand Down Expand Up @@ -173,13 +162,6 @@ def run_tests_in_sesssion(
if skip_flaky:
pytest_args.append('-m not slow and not flaky')

# session.posargs is any leftover arguments from the command line,
# which allows users to run a particular test instead of all of them.
if session.posargs:
sample_directories = session.posargs
elif sample_directories is None:
sample_directories = collect_sample_dirs('.', TESTS_BLACKLIST)

if changed_only:
changed_files = get_changed_files()
sample_directories = filter_samples(
Expand All @@ -204,43 +186,39 @@ def run_tests_in_sesssion(

@nox.parametrize('interpreter', ['python2.7', 'python3.4'])
def session_tests(session, interpreter):
"""Runs tests"""
run_tests_in_sesssion(session, interpreter)
"""Runs tests for all non-gae standard samples."""
# session.posargs is any leftover arguments from the command line,
# which allows users to run a particular test instead of all of them.
if session.posargs:
sample_directories = session.posargs
elif sample_directories is None:
sample_directories = collect_sample_dirs(
'.', set('./appengine/standard'))

run_tests_in_sesssion(session, interpreter, sample_directories)


def session_gae(session):
"""Runs test for GAE Standard samples."""
sample_directories = collect_sample_dirs('appengine/standard')
run_tests_in_sesssion(
session, 'python2.7', use_appengine=True,
sample_directories=collect_sample_dirs(
'appengine/standard',
APPENGINE_BLACKLIST))


def session_grpc(session):
"""Runs tests for samples that need grpc."""
# TODO: Remove this when grpc supports Python 3.
run_tests_in_sesssion(
session,
'python2.7',
sample_directories=itertools.chain(
collect_sample_dirs('speech'),
collect_sample_dirs('bigtable')))
session, 'python2.7', sample_directories, use_appengine=True)


@nox.parametrize('subsession', ['gae', 'tests'])
def session_travis(session, subsession):
"""On travis, just run with python3.4 and don't run slow or flaky tests."""
if subsession == 'tests':
sample_directories = collect_sample_dirs(
'.', set('./appengine/standard'))
run_tests_in_sesssion(
session, 'python3.4', skip_flaky=True, changed_only=True)
session, 'python3.4', sample_directories, skip_flaky=True,
changed_only=True)
else:
sample_directories = collect_sample_dirs('appengine/standard')
run_tests_in_sesssion(
session, 'python2.7', use_appengine=True, skip_flaky=True,
changed_only=True,
sample_directories=collect_sample_dirs(
'appengine/standard',
APPENGINE_BLACKLIST))
session, 'python2.7', sample_directories, use_appengine=True,
skip_flaky=True, changed_only=True)


def session_lint(session):
Expand Down
5 changes: 0 additions & 5 deletions speech/api/speech_async_grpc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@

import argparse
import re
import sys

import pytest
from speech_async_grpc import _gcs_uri
from speech_async_grpc import main


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

Expand Down
5 changes: 0 additions & 5 deletions speech/api/speech_grpc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@
# limitations under the License.

import re
import sys

import pytest
from speech_grpc import _gcs_uri
from speech_grpc import main


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

Expand Down
7 changes: 0 additions & 7 deletions speech/api/speech_streaming_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
import contextlib
import io
import re
import sys
import time

import pytest

import speech_streaming


Expand Down Expand Up @@ -57,10 +54,6 @@ def mock_audio_stream(channels, rate, chunk):
return mock_audio_stream


@pytest.mark.skipif(
sys.version_info >= (3, 0),
reason=("grpc doesn't yet support python3 "
'https://github.com/grpc/grpc/issues/282'))
def test_main(resource, monkeypatch, capsys):
monkeypatch.setattr(
speech_streaming, 'record_audio',
Expand Down