-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
169 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# coding: utf8 | ||
from __future__ import unicode_literals, print_function, division | ||
|
||
import pytest | ||
|
||
try: | ||
import pathlib2 as pathlib | ||
except ImportError: # pragma: no cover | ||
import pathlib | ||
|
||
|
||
@pytest.fixture | ||
def tmppath(tmpdir): | ||
return pathlib.Path(str(tmpdir)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,43 @@ | ||
# coding: utf8 | ||
from __future__ import unicode_literals, print_function, division | ||
from unittest import TestCase | ||
|
||
import attr | ||
import pytest | ||
|
||
from clldutils.apilib import API, DataObject, latitude, longitude | ||
|
||
class Tests(TestCase): | ||
def test_API(self): | ||
from clldutils.apilib import API | ||
|
||
api = API('.') | ||
assert api.repos.exists() | ||
self.assertIn('repository', '%s' % api) | ||
def test_API(): | ||
api = API('.') | ||
assert api.repos.exists() | ||
assert 'repository' in '%s' % api | ||
assert not api.path('unknown', 'path').exists() | ||
|
||
assert not api.path('unknown', 'path').exists() | ||
|
||
def test_DataObject(self): | ||
from clldutils.apilib import DataObject | ||
def test_DataObject(): | ||
@attr.s | ||
class C(DataObject): | ||
x = attr.ib() | ||
y = attr.ib(metadata=dict(ascsv=lambda v: 'xyz')) | ||
|
||
@attr.s | ||
class C(DataObject): | ||
x = attr.ib() | ||
y = attr.ib(metadata=dict(ascsv=lambda v: 'xyz')) | ||
assert C.fieldnames() == ['x', 'y'] | ||
assert C(None, 2).ascsv() == ['', 'xyz'] | ||
assert C(['y', 'x'], 2).ascsv() == ['y;x', 'xyz'] | ||
assert C({'y': 2}, 2).ascsv() == ['{"y": 2}', 'xyz'] | ||
assert C(2.123456, 'x').ascsv() == ['2.12346', 'xyz'] | ||
assert C(2, 'x').ascsv() == ['2', 'xyz'] | ||
|
||
self.assertEqual(C.fieldnames(), ['x', 'y']) | ||
self.assertEqual(C(None, 2).ascsv(), ['', 'xyz']) | ||
self.assertEqual(C(['y', 'x'], 2).ascsv(), ['y;x', 'xyz']) | ||
self.assertEqual(C({'y': 2}, 2).ascsv(), ['{"y": 2}', 'xyz']) | ||
self.assertEqual(C(2.123456, 'x').ascsv(), ['2.12346', 'xyz']) | ||
self.assertEqual(C(2, 'x').ascsv(), ['2', 'xyz']) | ||
|
||
def test_latitude_longitude(self): | ||
from clldutils.apilib import latitude, longitude | ||
def test_latitude_longitude(): | ||
@attr.s | ||
class C(object): | ||
lat = latitude() | ||
lon = longitude() | ||
|
||
@attr.s | ||
class C(object): | ||
lat = latitude() | ||
lon = longitude() | ||
assert C('', None).lat is None | ||
|
||
self.assertIsNone(C('', None).lat) | ||
with pytest.raises(ValueError): | ||
C(lat=100, lon=50) | ||
|
||
with self.assertRaises(ValueError): | ||
C(lat=100, lon=50) | ||
|
||
with self.assertRaises(ValueError): | ||
C(lat='10', lon='500') | ||
with pytest.raises(ValueError): | ||
C(lat='10', lon='500') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,44 @@ | ||
# coding: utf8 | ||
from __future__ import unicode_literals, print_function, division | ||
from unittest import TestCase | ||
|
||
import pytest | ||
|
||
class Tests(TestCase): | ||
def test_DeclEnum_int(self): | ||
from clldutils.declenum import DeclEnum | ||
from clldutils.declenum import DeclEnum | ||
|
||
class A(DeclEnum): | ||
val1 = 2, 'x' | ||
val2 = 3, 'y' | ||
val3 = 1, 'z' | ||
|
||
self.assertEqual(A.val1.name, 'val1') | ||
self.assertEqual('{0}'.format(A.val1), '2') | ||
self.assertGreater(A.val1, A.val3) | ||
self.assertGreater(A.val2, A.val1) | ||
self.assertEqual(A.val1, A.get(A.val1)) | ||
self.assertEqual(A.val1, A.get(2)) | ||
self.assertLess(A.get(1), A.get(3)) | ||
def test_DeclEnum_int(): | ||
class A(DeclEnum): | ||
val1 = 2, 'x' | ||
val2 = 3, 'y' | ||
val3 = 1, 'z' | ||
|
||
with self.assertRaises(ValueError): | ||
A.get(5) | ||
assert A.val1.name == 'val1' | ||
assert '{0}'.format(A.val1) == '2' | ||
assert A.val1 > A.val3 | ||
assert A.val2 > A.val1 | ||
assert A.val1 == A.get(A.val1) | ||
assert A.val1 == A.get(2) | ||
assert A.get(1) < A.get(3) | ||
|
||
d = {v: v.description for v in A} | ||
self.assertEqual(sorted(d)[0], A.val3) | ||
with pytest.raises(ValueError): | ||
A.get(5) | ||
|
||
def test_DeclEnum(self): | ||
from clldutils.declenum import DeclEnum | ||
d = {v: v.description for v in A} | ||
assert sorted(d)[0] == A.val3 | ||
|
||
class A(DeclEnum): | ||
val1 = '1', 'value 1' | ||
val2 = '2', 'value 2' | ||
|
||
for val, desc in A: | ||
self.assertEqual(val, '1') | ||
break | ||
def test_DeclEnum(): | ||
class A(DeclEnum): | ||
val1 = '1', 'value 1' | ||
val2 = '2', 'value 2' | ||
|
||
self.assertEqual(len(list(A.values())), 2) | ||
self.assertIn('1', repr(A.val1)) | ||
self.assertEqual(A.from_string('1'), A.val1) | ||
with self.assertRaises(ValueError): | ||
A.from_string('x') | ||
assert A.val1.__json__(None) == A.val1.__unicode__() | ||
for val, desc in A: | ||
assert val == '1' | ||
break | ||
|
||
assert len(list(A.values())) == 2 | ||
assert '1' in repr(A.val1) | ||
assert A.from_string('1') == A.val1 | ||
with pytest.raises(ValueError): | ||
A.from_string('x') | ||
assert A.val1.__json__(None) == A.val1.__unicode__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
from __future__ import unicode_literals | ||
|
||
from unittest import TestCase | ||
|
||
def test_replace(): | ||
from clldutils.lgr import replace | ||
|
||
class Tests(TestCase): | ||
for i, o in [ | ||
('1SG', '<first person singular>'), | ||
('DUR.DU-', '<durative>.<dual>-'), | ||
]: | ||
assert replace(i) == o | ||
|
||
def test_replace(self): | ||
from clldutils.lgr import replace | ||
|
||
for i, o in [ | ||
('1SG', '<first person singular>'), | ||
('DUR.DU-', '<durative>.<dual>-'), | ||
]: | ||
self.assertEqual(replace(i), o) | ||
|
||
self.assertEqual(replace('DUR.DU-', lambda m: m.group('pre') + '#'), '#.#-') | ||
self.assertEqual(replace('.XX-', custom={'XX': 'x'}), '.<x>-') | ||
assert replace('DUR.DU-', lambda m: m.group('pre') + '#') == '#.#-' | ||
assert replace('.XX-', custom={'XX': 'x'}) == '.<x>-' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
# coding: utf8 | ||
from __future__ import unicode_literals, print_function, division | ||
from unittest import TestCase | ||
|
||
|
||
class Tests(TestCase): | ||
def test_find(self): | ||
from clldutils.licenses import find | ||
def test_find(): | ||
from clldutils.licenses import find | ||
|
||
self.assertEqual( | ||
find('http://creativecommons.org/licenses/by/4.0').id, 'CC-BY-4.0') | ||
self.assertEqual( | ||
find('CC-BY-4.0').url, 'https://creativecommons.org/licenses/by/4.0/') | ||
assert find('http://creativecommons.org/licenses/by/4.0').id == 'CC-BY-4.0' | ||
assert find('CC-BY-4.0').url == 'https://creativecommons.org/licenses/by/4.0/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,20 @@ | ||
# coding: utf8 | ||
from __future__ import unicode_literals, print_function, division | ||
from unittest import TestCase | ||
from operator import itemgetter | ||
|
||
|
||
class Tests(TestCase): | ||
def test_Table(self): | ||
from clldutils.markup import Table | ||
def test_Table(): | ||
from clldutils.markup import Table | ||
|
||
t = Table() | ||
self.assertEqual(t.render(), '') | ||
t = Table() | ||
assert t.render() == '' | ||
|
||
t = Table('a', 'b', rows=[[1, 2], [3, 4]]) | ||
self.assertEqual( | ||
t.render(), | ||
'| a | b |\n|----:|----:|\n| 1 | 2 |\n| 3 | 4 |') | ||
self.assertEqual( | ||
t.render(condensed=False), | ||
'| a | b |\n|----:|----:|\n| 1 | 2 |\n| 3 | 4 |') | ||
self.assertEqual( | ||
t.render(verbose=True), | ||
'| a | b |\n|----:|----:|\n| 1 | 2 |\n| 3 | 4 |\n\n(2 rows)\n\n') | ||
self.assertEqual( | ||
t.render(sortkey=itemgetter(1), reverse=True), | ||
'| a | b |\n|----:|----:|\n| 3 | 4 |\n| 1 | 2 |') | ||
t = Table('a', 'b', rows=[[1, 2], [3, 4]]) | ||
assert t.render() == \ | ||
'| a | b |\n|----:|----:|\n| 1 | 2 |\n| 3 | 4 |' | ||
assert t.render(condensed=False) == \ | ||
'| a | b |\n|----:|----:|\n| 1 | 2 |\n| 3 | 4 |' | ||
assert t.render(verbose=True) == \ | ||
'| a | b |\n|----:|----:|\n| 1 | 2 |\n| 3 | 4 |\n\n(2 rows)\n\n' | ||
assert t.render(sortkey=itemgetter(1), reverse=True) == \ | ||
'| a | b |\n|----:|----:|\n| 3 | 4 |\n| 1 | 2 |' |
Oops, something went wrong.