Skip to content

Commit 72a5a3e

Browse files
committed
Merge pull request #15 from hayd/metrics
Metrics
2 parents e7399ac + 5242e84 commit 72a5a3e

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.dev*
33
*.nja
44
*.egg-info
5+
*.db
56

67
.tox
78
build
@@ -13,4 +14,4 @@ test/pattern_unittest_db
1314
pattern_unittest_db
1415
examples/06-graph/test/
1516

16-
.DS_Store
17+
.DS_Store

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ python:
1010
matrix:
1111
allow_failures:
1212
- python: "3.3"
13-
- python: "3.4"
1413
- python: "pypy"
1514

1615
install:
@@ -23,7 +22,11 @@ script:
2322
# test_05vector_07slp takes too long (so travis errors the build), it also fails on py2!
2423
# TODO make test_05vector_07slp run faster (or do slightly less).
2524
# TODO perhaps split build into tests and examples?
26-
- nosetests --exclude=test_05vector_07slp --with-coverage --cover-package=pattern
25+
# For now we only run the passing python 3 tests are run on the 3.4 build
26+
- if [ "$TRAVIS_PYTHON_VERSION" == "3.4" ]; then
27+
nosetests test/test_graph.py test/test_metrics.py; else
28+
nosetests --exclude=test_05vector_07slp --with-coverage --cover-package=pattern;
29+
fi
2730

2831
after_success:
2932
- pip install --quiet coveralls

pattern/db/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ def SQL(self, **kwargs):
15521552
>>> FilterChain(
15531553
>>> filter("tail", True),
15541554
>>> filter("wing", True), operator=OR))
1555-
Yields:
1555+
Yields:
15561556
"type='pet' and weight between 4 and 6 and (tail=1 or wing=1)"
15571557
"""
15581558
# Remember to pass the right escape() function as optional parameter.
@@ -1836,7 +1836,7 @@ def render(self, *path, **query):
18361836
""" This method should be overwritten to return formatted table output (XML, HTML, RSS, ...)
18371837
For web apps, the given path should list all parts in the relative URL path,
18381838
and query is a dictionary of all POST and GET variables sent from the client.
1839-
For example: http://books.com/science/new
1839+
For example: http://books.com/science/new
18401840
=> ["science", "new"]
18411841
=> render() data from db.books.filter(ALL, category="science", new=True).
18421842
"""
@@ -2226,7 +2226,8 @@ def load(cls, path, separator=",", decoder=lambda v: v, headers=False, preproces
22262226
data = data if not password else StringIO(
22272227
data.replace("\r\n", "\n").replace("\r", "\n"))
22282228
data = data if not preprocess else StringIO(preprocess(data.read()))
2229-
data.seek(data.readline().startswith(BOM_UTF8) and len(BOM_UTF8) or 0)
2229+
bom_utf8 = BOM_UTF8 if sys.version < "3" else BOM_UTF8.decode("utf-8")
2230+
data.seek(data.readline().startswith(bom_utf8) and len(BOM_UTF8) or 0)
22302231
data = csvlib.reader(data, delimiter=separator)
22312232
i, n = kwargs.get("start"), kwargs.get("count")
22322233
if i is not None and n is not None:

test/test_metrics.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,18 @@ def test_suffixes(self):
164164
# Assert base => inflected and reversed inflected => base suffixes.
165165
s = [("beau", "beaux"), ("jeune", "jeunes"), ("hautain", "hautaines")]
166166
v = metrics.suffixes(s, n=3)
167-
self.assertEqual(v, [
168-
(2, "nes", [("ne", 0.5), ("n", 0.5)]),
169-
(1, "aux", [("au", 1.0)])])
167+
v[0][2].sort() # order is not well-defined in python 3
168+
expected = [
169+
(2, "nes", [("n", 0.5), ("ne", 0.5)]),
170+
(1, "aux", [("au", 1.0)])]
171+
self.assertEqual(v, expected)
172+
170173
v = metrics.suffixes(s, n=2, reverse=False)
171-
self.assertEqual(v, [
174+
expected = [
172175
(1, "ne", [("nes", 1.0)]),
173176
(1, "in", [("ines", 1.0)]),
174-
(1, "au", [("aux", 1.0)])])
177+
(1, "au", [("aux", 1.0)])]
178+
self.assertEqual(v, expected)
175179
print("pattern.metrics.suffixes()")
176180

177181
def test_isplit(self):

0 commit comments

Comments
 (0)