-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for access functions. Closes #44.
- Loading branch information
Showing
8 changed files
with
196 additions
and
22 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
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
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env python | ||
|
||
try: | ||
import unittest2 as unittest | ||
except ImportError: | ||
import unittest | ||
|
||
import leather | ||
from leather.utils import X, Y | ||
|
||
|
||
class TestSeries(unittest.TestCase): | ||
def setUp(self): | ||
self.shape = leather.Dots('red') | ||
|
||
def test_pairs(self): | ||
data = [ | ||
('foo', 1), | ||
('bar', 2), | ||
('baz', 3) | ||
] | ||
|
||
series = leather.Series(data, self.shape) | ||
|
||
self.assertSequenceEqual(series.values(X), ['foo', 'bar', 'baz']) | ||
self.assertSequenceEqual(series.values(Y), [1, 2, 3]) | ||
|
||
def test_lists(self): | ||
data = [ | ||
('foo', 1, 4), | ||
('bar', 2, 5), | ||
('baz', 3, 6) | ||
] | ||
|
||
series = leather.Series(data, self.shape) | ||
|
||
self.assertSequenceEqual(series.values(X), ['foo', 'bar', 'baz']) | ||
self.assertSequenceEqual(series.values(Y), [1, 2, 3]) | ||
|
||
series = leather.Series(data, self.shape, x=2, y=0) | ||
|
||
self.assertSequenceEqual(series.values(X), [4, 5, 6]) | ||
self.assertSequenceEqual(series.values(Y), ['foo', 'bar', 'baz']) | ||
|
||
with self.assertRaises(TypeError): | ||
series = leather.Series(data, self.shape, x='words') | ||
|
||
def test_dicts(self): | ||
data = [ | ||
{'a': 'foo', 'b': 1, 'c': 4}, | ||
{'a': 'bar', 'b': 2, 'c': 5}, | ||
{'a': 'baz', 'b': 3, 'c': 6} | ||
] | ||
|
||
with self.assertRaises(TypeError): | ||
series = leather.Series(data, self.shape) | ||
|
||
series = leather.Series(data, self.shape, x='c', y='a') | ||
|
||
self.assertSequenceEqual(series.values(X), [4, 5, 6]) | ||
self.assertSequenceEqual(series.values(Y), ['foo', 'bar', 'baz']) | ||
|
||
def test_custom(self): | ||
class Obj(object): | ||
def __init__(self, a, b, c): | ||
self.a = a | ||
self.b = b | ||
self.c =c | ||
|
||
data = [ | ||
Obj('foo', 1, 4), | ||
Obj('bar', 2, 5), | ||
Obj('baz', 3, 6) | ||
] | ||
|
||
with self.assertRaises(TypeError): | ||
series = leather.Series(data, self.shape) | ||
|
||
with self.assertRaises(TypeError): | ||
series = leather.Series(data, self.shape, x='words', y='more') | ||
|
||
def get_x(row, i): | ||
return row.b | ||
|
||
def get_y(row, i): | ||
return row.c | ||
|
||
series = leather.Series(data, self.shape, x=get_x, y=get_y) | ||
|
||
self.assertSequenceEqual(series.values(X), [1, 2, 3]) | ||
self.assertSequenceEqual(series.values(Y), [4, 5, 6]) |