diff options
| author | Cory Benfield <lukasaoz@gmail.com> | 2016-09-14 08:10:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-09-14 08:10:28 +0100 |
| commit | 5524472cc76ea00d64181505f1fbb7f93f11cc2b (patch) | |
| tree | efaec1150e954ec4b18d3d723b8f10fc11501208 /tests/test_utils.py | |
| parent | 2041adbe4d86539825a35860246ec0f465b7df3d (diff) | |
| parent | f5c59743e7a45b68eaa82c83baaaed5607348afe (diff) | |
| download | python-requests-5524472cc76ea00d64181505f1fbb7f93f11cc2b.tar.gz | |
Merge pull request #3535 from nateprewitt/3339_avoid_getvalues
avoid use of getvalues in super_len
Diffstat (limited to 'tests/test_utils.py')
| -rw-r--r-- | tests/test_utils.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py index 03cff7a6..7e0b4f28 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -66,6 +66,34 @@ class TestSuperLen: assert super_len(fd) == 4 assert len(recwarn) == warnings_num + def test_super_len_with__len__(self): + foo = [1,2,3,4] + len_foo = super_len(foo) + assert len_foo == 4 + + def test_super_len_with_no__len__(self): + class LenFile(object): + def __init__(self): + self.len = 5 + + assert super_len(LenFile()) == 5 + + def test_super_len_with_tell(self): + foo = StringIO.StringIO('12345') + assert super_len(foo) == 5 + foo.read(2) + assert super_len(foo) == 3 + + def test_super_len_with_fileno(self): + with open(__file__, 'rb') as f: + length = super_len(f) + file_data = f.read() + assert length == len(file_data) + + def test_super_len_with_no_matches(self): + """Ensure that objects without any length methods default to 0""" + assert super_len(object()) == 0 + class TestToKeyValList: |
