Skip to content

Commit

Permalink
Using tox for testing and adding coveralls for Travis.
Browse files Browse the repository at this point in the history
Also
- Removing cover/runtests rules from Makefile.
- Renaming context_test.ContextTests.start_test_server as a
  protected method so nosetests doesn't pick it up.
- Removing docstrings from test cases so they display properly
  in verbose nosetest output.
- Using "--logging-level=INFO" with nosetests. If not, __repr__
  would cause a failure for
    model_test.ModelTests.testLocalStructuredPropertyKeyDisagreement
  since other1.inner has an invalid Kind.
- Adding setup.py in order to use tox.
- Turning commented out unit-tests into "unittest.skip".
- Updating README / CONTRIBUTING to reflect test changes.
- Adding coveralls badge to README.
- Excluding test modules and google_imports helper from
  line coverage.
- Removing un-needed PYTHONPATH=. from Makefile.
  • Loading branch information
dhermes committed Jan 13, 2015
1 parent 3e9c3aa commit bdc9849
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 105 deletions.
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[run]
branch = True
[report]
omit =
*test*
ndb/google_imports.py
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ before_install:
- ./get_app_engine_sdk.sh
- export GAE="./cache/google_appengine"

install:
- pip install tox

script:
- make runtests
- tox -e py27

after_success:
- tox -e coveralls
14 changes: 11 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ Running Tests
- To run all tests for `ndb`, run

```
$ make runtests
$ tox -e py27
```

or

```
$ make runtests GAE=${PATH_TO_GAE_SDK}
$ GAE=${PATH_TO_GAE_SDK} tox -e py27
```

where the environment variable `GAE` is the path to to Google App
Expand All @@ -110,7 +110,15 @@ Running Tests
`${GOOGLE_CLOUD_SDK}/platform/google_appengine` (as of January 2014).

You can export this path as the `${GAE}` environment variable and
then tests can be run simply as `make runtests`.
then tests can be run simply as `tox -e py27`.

- To see test coverage, run

```
tox -e cover
```

where as above `GAE` should be set.

Contributor License Agreements
------------------------------
Expand Down
45 changes: 17 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@

FLAGS=
export GAE?= /usr/local/google_appengine
NONTESTS=`find ndb -name [a-z]\*.py ! -name \*_test.py`
PYTHON= python -Wignore
COVERAGE=coverage
APPCFG= $(GAE)/../../bin/appcfg.py
DEV_APPSERVER=$(GAE)/../../bin/dev_appserver.py
DATASTORE_PATH=/tmp/ndb-dev_appserver.datastore
PORT= 8080
HOST= localhost
APP_ID=
APP_VERSION=

help:
@echo 'Makefile for NDB for Google App Engine '
@echo ' '
@echo 'Usage: '
@echo ' make runtests Run all unit tests '
@echo ' make coverage Report test coverage '
@echo ' make serve Serve sample app locally '
@echo ' make deploy Deploy sample app '
@echo ' make bench Task creation benchmark '
Expand All @@ -41,58 +39,49 @@ help:
@echo 'NOTE: This file is being wound down and will be fully '
@echo ' replaced by tox.ini. '

runtests ndb_test:
PYTHONPATH=. $(PYTHON) ndb/ndb_test.py $(FLAGS)

c cov cove cover coverage:
PYTHONPATH=. $(COVERAGE) run ndb/ndb_test.py $(FLAGS)
$(COVERAGE) html $(NONTESTS)
$(COVERAGE) report -m $(NONTESTS)
echo "open file://`pwd`/htmlcov/index.html"

serve:
$(PYTHON) $(DEV_APPSERVER) demo/ --port $(PORT) --host $(HOST) $(FLAGS) --datastore_path=$(DATASTORE_PATH)

deploy:
$(PYTHON) $(APPCFG) update demo/ --application=$(APP_ID) --version=$(APP_VERSION) $(FLAGS)

bench:
PYTHONPATH=. $(PYTHON) benchmarks/bench.py $(FLAGS)
$(PYTHON) benchmarks/bench.py $(FLAGS)

key_bench:
PYTHONPATH=. $(PYTHON) benchmarks/key_bench.py $(FLAGS)
$(PYTHON) benchmarks/key_bench.py $(FLAGS)

put_bench:
PYTHONPATH=. $(PYTHON) benchmarks/put_bench.py $(FLAGS)
$(PYTHON) benchmarks/put_bench.py $(FLAGS)

db_keys_only_bench:
PYTHONPATH=. $(PYTHON) benchmarks/db_keys_only_bench.py $(FLAGS)
$(PYTHON) benchmarks/db_keys_only_bench.py $(FLAGS)

ndb_keys_only_bench:
PYTHONPATH=. $(PYTHON) benchmarks/ndb_keys_only_bench.py $(FLAGS)
$(PYTHON) benchmarks/ndb_keys_only_bench.py $(FLAGS)

repl:
PYTHONPATH=. $(PYTHON) -i development_tools/ndb_repl.py $(FLAGS)
$(PYTHON) -i development_tools/ndb_repl.py $(FLAGS)

gql:
PYTHONPATH=. $(PYTHON) development_tools/gql_repl.py $(FLAGS)
$(PYTHON) development_tools/gql_repl.py $(FLAGS)

longlines:
$(PYTHON) longlines.py

tr trim trimwhitespace:
trimwhitespace:
$(PYTHON) trimwhitespace.py

g get_tasklet_race:
PYTHONPATH=. $(PYTHON) benchmarks/get_tasklet_race.py $(FLAGS)
get_tasklet_race:
$(PYTHON) benchmarks/get_tasklet_race.py $(FLAGS)

s stress:
PYTHONPATH=. $(PYTHON) benchmarks/stress.py $(FLAGS)
stress:
$(PYTHON) benchmarks/stress.py $(FLAGS)

race:
PYTHONPATH=. $(PYTHON) benchmarks/race.py $(FLAGS)
$(PYTHON) benchmarks/race.py $(FLAGS)

multithread_test:
PYTHONPATH=. $(PYTHON) benchmarks/multithread_test.py $(FLAGS)
$(PYTHON) benchmarks/multithread_test.py $(FLAGS)

.PHONY: help runtests coverage serve deploy bench key_bench put_bench db_keys_only_bench ndb_keys_only_bench repl gql longlines trimwhitespace get_tasklet_race stress race multithread_test
.PHONY: help serve deploy bench key_bench put_bench db_keys_only_bench ndb_keys_only_bench repl gql longlines trimwhitespace get_tasklet_race stress race multithread_test
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Google App Engine NDB Library

[![Travis Build Status](https://travis-ci.org/dhermes/ndb-git.svg?branch=master)](https://travis-ci.org/dhermes/ndb-git)
[![Coverage Status](https://img.shields.io/coveralls/dhermes/ndb-git.svg)](https://coveralls.io/r/dhermes/ndb-git?branch=master)

This is a `git` port of [`appengine-ndb-experiment`][2] (a Mercurial
This is a `git` port of [`appengine-ndb-experiment`][1] (a Mercurial
project). This was imported via

```
Expand Down Expand Up @@ -121,13 +122,6 @@ for repository management and continuous integration.
How To
------

To run the tests with coverage, install the `coverage.py` [package][1]
and then use

```
make coverage
```

To run the demo app on `localhost:8080`, use

```
Expand All @@ -144,10 +138,9 @@ make repl
See the `Makefile` for more details; run

```
make repl
make
```

for a help message.

[1]: http://nedbatchelder.com/code/coverage/
[2]: https://code.google.com/p/appengine-ndb-experiment/
[1]: https://code.google.com/p/appengine-ndb-experiment/
4 changes: 2 additions & 2 deletions ndb/context_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ def mock_create_rpc(deadline='invalid'):
finally:
memcache.create_rpc = orig_create_rpc

def start_test_server(self):
def _start_test_server(self):
host = '127.0.0.1'
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Expand All @@ -1382,7 +1382,7 @@ def run():

def testUrlFetch(self):
self.testbed.init_urlfetch_stub()
host, port = self.start_test_server()
host, port = self._start_test_server()
fut = self.ctx.urlfetch('http://%s:%d' % (host, port))
result = fut.get_result()
self.assertEqual(result.status_code, 200)
Expand Down
2 changes: 0 additions & 2 deletions ndb/metadata_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def testDirectPropertyQueries(self):
[(p.kind_name, p.property_name) for p in res])

def testEntityGroup(self):
"""Test for EntityGroup class."""
self.HRTest()
foo_e = self.Foo(age=11)
foo_e.put()
Expand All @@ -124,7 +123,6 @@ def testEntityGroup(self):
self.assertTrue(egfoo_k.get().version > v1)

def testGetEntityGroupVersion(self):
"""Test for get_entity_group_version function."""
self.HRTest()
foo_e = self.Foo(age=11)
foo_e.put()
Expand Down
33 changes: 0 additions & 33 deletions ndb/ndb_test.py

This file was deleted.

43 changes: 29 additions & 14 deletions ndb/query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,19 @@ class Emp(model.Model):
lambda: Emp.sub.booh == 42)
self.assertRaises(datastore_errors.BadFilterError,
lambda: Emp.struct == Foo(name='a'))
self.assertRaises(datastore_errors.BadFilterError,
lambda: Emp.local == Foo(name='a'))
return Emp

@unittest.skip('BadFilterError is not raised.')
def testQueryUnindexedBadFilterFails(self):
Emp = self.testQueryUnindexedFails()
# TODO: Make this fail? See issue 89. http://goo.gl/K4gbY
# Currently StructuredProperty(..., indexed=False) has no effect.
## self.assertRaises(datastore_errors.BadFilterError,
## lambda: Emp.struct.name == 'a')
self.assertRaises(datastore_errors.BadFilterError,
lambda: Emp.local == Foo(name='a'))
lambda: Emp.struct.name == 'a')
# Once fixed, this case should be removed and the assert moved
# back into `testQueryUnindexedFails`.

def testConstructor(self):
self.ExpectWarnings()
Expand Down Expand Up @@ -970,7 +977,6 @@ def testCursorsEfficientPaging(self):
# TODO: Assert that only one RPC call was made.

def testCursorsDelete(self):
"""Tests that deleting an entity doesn't affect cursor positioning."""
class DeletedEntity(model.Model):
name = model.StringProperty()
entities = [DeletedEntity(name='A'),
Expand Down Expand Up @@ -1564,10 +1570,10 @@ def testGqlLimitOffsetQueryUsingFetch(self):
self.checkGql([self.jill], "SELECT * FROM Foo LIMIT 1 OFFSET 1",
fetch=lambda q: q.fetch())

# XXX TODO: Make this work:
## def testGqlLimitQueryUsingFetch(self):
## self.checkGql([self.joe, self.jill], "SELECT * FROM Foo LIMIT 2",
## fetch=lambda q: q.fetch(3))
@unittest.skip('GQL Fetch currently fails.')
def testGqlLimitQueryUsingFetch(self):
self.checkGql([self.joe, self.jill], "SELECT * FROM Foo LIMIT 2",
fetch=lambda q: q.fetch(3))

def testGqlOffsetQueryUsingFetchPage(self):
q = query.gql("SELECT * FROM Foo LIMIT 2")
Expand All @@ -1576,12 +1582,21 @@ def testGqlOffsetQueryUsingFetchPage(self):
self.assertEqual(True, more1)
res2, cur2, more2 = q.fetch_page(1, start_cursor=cur1)
self.assertEqual([self.jill], res2)
# XXX TODO: Gotta make this work:
## self.assertEqual(False, more2)
## res3, cur3, more3 = q.fetch_page(1, start_cursor=cur2)
## self.assertEqual([], res3)
## self.assertEqual(False, more3)
## self.assertEqual(None, cur3)

@unittest.skip('More results should be False')
def testGqlOffsetQuerySubsequent(self):
q = query.gql("SELECT * FROM Foo LIMIT 2")
res1, cur1, more1 = q.fetch_page(1)
self.assertEqual([self.joe], res1)
self.assertEqual(True, more1)
res2, cur2, more2 = q.fetch_page(1, start_cursor=cur1)
self.assertEqual([self.jill], res2)

self.assertEqual(False, more2)
res3, cur3, more3 = q.fetch_page(1, start_cursor=cur2)
self.assertEqual([], res3)
self.assertEqual(False, more3)
self.assertEqual(None, cur3)

def testGqlLimitQueryUsingFetchPage(self):
q = query.gql("SELECT * FROM Foo OFFSET 1")
Expand Down

0 comments on commit bdc9849

Please sign in to comment.