summaryrefslogtreecommitdiffstats
path: root/testing/talos/tests/test_filter.py
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/talos/tests/test_filter.py
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/talos/tests/test_filter.py')
-rwxr-xr-xtesting/talos/tests/test_filter.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/testing/talos/tests/test_filter.py b/testing/talos/tests/test_filter.py
new file mode 100755
index 000000000..b4e2d39cf
--- /dev/null
+++ b/testing/talos/tests/test_filter.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+
+"""
+test talos' filter module:
+
+http://hg.mozilla.org/build/talos/file/tip/talos/filter.py
+"""
+
+import unittest
+import talos.filter
+
+
+class TestFilter(unittest.TestCase):
+
+ data = range(30) # test data
+
+ def test_ignore(self):
+ """test the ignore filter"""
+ # a bit of a stub sanity test for a single filter
+
+ filtered = talos.filter.ignore_first(self.data)
+ self.assertEquals(filtered, self.data[1:])
+
+ filtered = talos.filter.ignore_first(self.data, 10)
+ self.assertEquals(filtered, self.data[10:])
+
+ # short series won't be filtered
+ filtered = talos.filter.ignore_first(self.data, 50)
+ self.assertEquals(filtered, self.data)
+
+ def test_getting_filters(self):
+ """test getting a list of filters from a string"""
+
+ filter_names = ['ignore_max', 'ignore_max', 'max']
+
+ # get the filter functions
+ filters = talos.filter.filters(*filter_names)
+ self.assertEquals(len(filter_names), len(filters))
+ for filter in filters:
+ self.assertTrue(self, hasattr(filter, '__call__'))
+
+ # apply them on the data
+ filtered = talos.filter.apply(self.data, filters)
+ self.assertEquals(filtered, 27)
+
+ def test_parse(self):
+ """test the filter name parse function"""
+
+ # an example with no arguments
+ parsed = talos.filter.parse('mean')
+ self.assertEquals(parsed, ['mean', []])
+
+ # an example with one integer argument
+ parsed = talos.filter.parse('ignore_first:10')
+ self.assertEquals(parsed, ['ignore_first', [10]])
+ self.assertEquals(type(parsed[1][0]), int)
+ self.assertNotEqual(type(parsed[1][0]), float)
+
+ # an example with several arguments
+
+ # temporarily add foo
+ # value is lambda function to mimic filter_dict key:value pair
+ talos.filter.scalar_filters['foo'] = lambda *args: args
+ parsed = talos.filter.parse('foo:10.1,2,5.0,6.')
+ self.assertEquals(parsed, ['foo', [10.1, 2, 5.0, 6.0]])
+ for index in (2, 3):
+ self.assertEquals(type(parsed[1][index]), float)
+ self.assertNotEqual(type(parsed[1][index]), int)
+
+ # an example that should fail
+ self.assertRaises(ValueError, talos.filter.parse, 'foo:bar')
+ self.assertRaises(ValueError, talos.filter.parse, 'foo:1,')
+
+ # delete foo again
+ del talos.filter.scalar_filters['foo']
+
+if __name__ == '__main__':
+ unittest.main()