[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Python3 unit test fixes
commit 2f0dc11f7e9bb4ee11e3c543ed993f4e7361987d
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Fri Jul 26 14:50:45 2019 -0700
Python3 unit test fixes
Handful of tweaks to fix python3 compatability for our unit tests. Non-test
changes are just non-behavioral (just renaming and such).
---
stem/descriptor/collector.py | 32 +++++++++++++++++---------------
test/unit/descriptor/collector.py | 12 ++++++------
2 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/stem/descriptor/collector.py b/stem/descriptor/collector.py
index 1f7ddb96..69425dd5 100644
--- a/stem/descriptor/collector.py
+++ b/stem/descriptor/collector.py
@@ -432,21 +432,21 @@ class CollecTor(object):
matches = []
- for entry in self._cached_files:
- if start and (entry.start is None or entry.start < start):
+ for f in self._cached_files:
+ if start and (f.start is None or f.start < start):
continue
- elif end and (entry.end is None or entry.end > end):
+ elif end and (f.end is None or f.end > end):
continue
- if descriptor_type is None or any([desc_type.startswith(descriptor_type) for desc_type in entry._guess_descriptor_types()]):
- matches.append(entry)
+ if descriptor_type is None or any([desc_type.startswith(descriptor_type) for desc_type in f._guess_descriptor_types()]):
+ matches.append(f)
return matches
@staticmethod
def _files(val, path):
"""
- Provies a mapping of paths to files within the index.
+ Recursively provies files within the index.
:param dict val: index hash
:param list path: path we've transversed into
@@ -454,16 +454,18 @@ class CollecTor(object):
:returns: **list** of :class:`~stem.descriptor.collector.File`
"""
+ if not isinstance(val, dict):
+ return [] # leaf node without any files
+
files = []
- if isinstance(val, dict):
- for k, v in val.items():
- if k == 'files':
- for attr in v:
- file_path = '/'.join(path + [attr.get('path')])
- files.append(File(file_path, attr.get('size'), attr.get('last_modified')))
- elif k == 'directories':
- for attr in v:
- files.extend(CollecTor._files(attr, path + [attr.get('path')]))
+ for k, v in val.items():
+ if k == 'files':
+ for attr in v:
+ file_path = '/'.join(path + [attr.get('path')])
+ files.append(File(file_path, attr.get('size'), attr.get('last_modified')))
+ elif k == 'directories':
+ for attr in v:
+ files.extend(CollecTor._files(attr, path + [attr.get('path')]))
return files
diff --git a/test/unit/descriptor/collector.py b/test/unit/descriptor/collector.py
index 914b52b9..ad0087dd 100644
--- a/test/unit/descriptor/collector.py
+++ b/test/unit/descriptor/collector.py
@@ -79,7 +79,7 @@ class TestCollector(unittest.TestCase):
collector = CollecTor()
self.assertEqual(MINIMAL_INDEX, collector.index(Compression.LZMA))
- urlopen_mock.assert_called_with('https://collector.torproject.org/index/index.json.lzma', timeout = None)
+ urlopen_mock.assert_called_with('https://collector.torproject.org/index/index.json.xz', timeout = None)
@patch(URL_OPEN)
def test_download_retries(self, urlopen_mock):
@@ -131,7 +131,7 @@ class TestCollector(unittest.TestCase):
self.assertEqual(85, len(files))
test_path = 'archive/relay-descriptors/extra-infos/extra-infos-2007-09.tar.xz'
- extrainfo_file = filter(lambda x: x.path == test_path, files)[0]
+ extrainfo_file = list(filter(lambda x: x.path == test_path, files))[0]
self.assertEqual(test_path, extrainfo_file.path)
self.assertEqual(Compression.LZMA, extrainfo_file.compression)
self.assertEqual(True, extrainfo_file.tar)
@@ -185,7 +185,7 @@ class TestCollector(unittest.TestCase):
'recent/relay-descriptors/server-descriptors/2019-07-03-04-05-00-server-descriptors',
]
- self.assertEqual(expected, map(lambda x: x.path, collector.files(descriptor_type = 'server-descriptor')))
+ self.assertEqual(expected, list(map(lambda x: x.path, collector.files(descriptor_type = 'server-descriptor'))))
@patch('stem.descriptor.collector.CollecTor.index', Mock(return_value = EXAMPLE_INDEX))
def test_file_query_by_date(self):
@@ -195,17 +195,17 @@ class TestCollector(unittest.TestCase):
'recent/relay-descriptors/server-descriptors/2019-07-03-02-05-00-server-descriptors',
'recent/relay-descriptors/server-descriptors/2019-07-03-03-05-00-server-descriptors',
'recent/relay-descriptors/server-descriptors/2019-07-03-04-05-00-server-descriptors',
- ], map(lambda x: x.path, collector.files(descriptor_type = 'server-descriptor', start = datetime.datetime(2007, 1, 1))))
+ ], list(map(lambda x: x.path, collector.files(descriptor_type = 'server-descriptor', start = datetime.datetime(2007, 1, 1)))))
self.assertEqual([
'archive/relay-descriptors/server-descriptors/server-descriptors-2005-12.tar.xz',
'archive/relay-descriptors/server-descriptors/server-descriptors-2006-02.tar.xz',
'archive/relay-descriptors/server-descriptors/server-descriptors-2006-03.tar.xz',
- ], map(lambda x: x.path, collector.files(descriptor_type = 'server-descriptor', end = datetime.datetime(2007, 1, 1))))
+ ], list(map(lambda x: x.path, collector.files(descriptor_type = 'server-descriptor', end = datetime.datetime(2007, 1, 1)))))
self.assertEqual([
'archive/relay-descriptors/server-descriptors/server-descriptors-2006-03.tar.xz',
- ], map(lambda x: x.path, collector.files(descriptor_type = 'server-descriptor', start = datetime.datetime(2006, 2, 10), end = datetime.datetime(2007, 1, 1))))
+ ], list(map(lambda x: x.path, collector.files(descriptor_type = 'server-descriptor', start = datetime.datetime(2006, 2, 10), end = datetime.datetime(2007, 1, 1)))))
def test_guess_descriptor_types(self):
f = File('archive/bridge-descriptors/extra-infos/bridge-extra-infos-2008-05.tar.xz', 377644, '2016-09-04 09:21')
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits