afscgap.test.test_query_util

 1import unittest
 2
 3import afscgap.query_util
 4
 5
 6class QueryUtilTests(unittest.TestCase):
 7
 8    def test_ords_none(self):
 9        result = afscgap.query_util.interpret_query_to_ords({'test': None})
10        self.assertIsNone(result['test'])
11
12    def test_ords_str(self):
13        result = afscgap.query_util.interpret_query_to_ords({'test': 'a'})
14        self.assertEquals(result['test'], 'a')
15
16    def test_ords_float(self):
17        result = afscgap.query_util.interpret_query_to_ords({'test': 1.23})
18        self.assertAlmostEquals(result['test'], 1.23)
19
20    def test_ords_int(self):
21        result = afscgap.query_util.interpret_query_to_ords({'test': 123})
22        self.assertAlmostEquals(result['test'], 123)
23
24    def test_ords_dict(self):
25        result = afscgap.query_util.interpret_query_to_ords({
26            'test': {'a': 1, 'b': '2'}
27        })
28        self.assertEquals(result['test']['a'], 1)
29        self.assertEquals(result['test']['b'], '2')
30
31    def test_ords_limit_lower_bound(self):
32        result = afscgap.query_util.interpret_query_to_ords({'test': (1, None)})
33        self.assertEquals(result['test']['$gte'], 1)
34
35    def test_ords_limit_upper_bound(self):
36        result = afscgap.query_util.interpret_query_to_ords({'test': (None, 1)})
37        self.assertEquals(result['test']['$lte'], 1)
38
39    def test_ords_limit_range(self):
40        result = afscgap.query_util.interpret_query_to_ords({'test': (1, 2)})
41        self.assertEquals(result['test']['$between'][0], 1)
42        self.assertEquals(result['test']['$between'][1], 2)
43
44    def test_py_none(self):
45        result = afscgap.query_util.interpret_query_to_py({'test': None})
46        self.assertIsNone(result['test'])
47
48    def test_py_str(self):
49        result = afscgap.query_util.interpret_query_to_py({'test': 'a'})
50        self.assertTrue(result['test']('a'))
51        self.assertFalse(result['test']('b'))
52
53    def test_py_float(self):
54        result = afscgap.query_util.interpret_query_to_py({'test': 1.23})
55        self.assertTrue(result['test'](1.23))
56        self.assertFalse(result['test'](1.24))
57
58    def test_py_int(self):
59        result = afscgap.query_util.interpret_query_to_py({'test': 123})
60        self.assertTrue(result['test'](123))
61        self.assertFalse(result['test'](124))
62
63    def test_py_dict(self):
64        with self.assertRaises(RuntimeError):
65            afscgap.query_util.interpret_query_to_py({
66                'test': {'a': 1, 'b': '2'}
67            })
68
69    def test_py_limit_lower_bound(self):
70        result = afscgap.query_util.interpret_query_to_py({'test': (1, None)})
71        self.assertTrue(result['test'](123))
72        self.assertFalse(result['test'](0))
73
74    def test_py_limit_upper_bound(self):
75        result = afscgap.query_util.interpret_query_to_py({'test': (None, 1)})
76        self.assertTrue(result['test'](0))
77        self.assertFalse(result['test'](2))
78
79    def test_py_limit_range(self):
80        result = afscgap.query_util.interpret_query_to_py({'test': (1, 2)})
81        self.assertTrue(result['test'](1.5))
82        self.assertFalse(result['test'](3))
class QueryUtilTests(unittest.case.TestCase):
 7class QueryUtilTests(unittest.TestCase):
 8
 9    def test_ords_none(self):
10        result = afscgap.query_util.interpret_query_to_ords({'test': None})
11        self.assertIsNone(result['test'])
12
13    def test_ords_str(self):
14        result = afscgap.query_util.interpret_query_to_ords({'test': 'a'})
15        self.assertEquals(result['test'], 'a')
16
17    def test_ords_float(self):
18        result = afscgap.query_util.interpret_query_to_ords({'test': 1.23})
19        self.assertAlmostEquals(result['test'], 1.23)
20
21    def test_ords_int(self):
22        result = afscgap.query_util.interpret_query_to_ords({'test': 123})
23        self.assertAlmostEquals(result['test'], 123)
24
25    def test_ords_dict(self):
26        result = afscgap.query_util.interpret_query_to_ords({
27            'test': {'a': 1, 'b': '2'}
28        })
29        self.assertEquals(result['test']['a'], 1)
30        self.assertEquals(result['test']['b'], '2')
31
32    def test_ords_limit_lower_bound(self):
33        result = afscgap.query_util.interpret_query_to_ords({'test': (1, None)})
34        self.assertEquals(result['test']['$gte'], 1)
35
36    def test_ords_limit_upper_bound(self):
37        result = afscgap.query_util.interpret_query_to_ords({'test': (None, 1)})
38        self.assertEquals(result['test']['$lte'], 1)
39
40    def test_ords_limit_range(self):
41        result = afscgap.query_util.interpret_query_to_ords({'test': (1, 2)})
42        self.assertEquals(result['test']['$between'][0], 1)
43        self.assertEquals(result['test']['$between'][1], 2)
44
45    def test_py_none(self):
46        result = afscgap.query_util.interpret_query_to_py({'test': None})
47        self.assertIsNone(result['test'])
48
49    def test_py_str(self):
50        result = afscgap.query_util.interpret_query_to_py({'test': 'a'})
51        self.assertTrue(result['test']('a'))
52        self.assertFalse(result['test']('b'))
53
54    def test_py_float(self):
55        result = afscgap.query_util.interpret_query_to_py({'test': 1.23})
56        self.assertTrue(result['test'](1.23))
57        self.assertFalse(result['test'](1.24))
58
59    def test_py_int(self):
60        result = afscgap.query_util.interpret_query_to_py({'test': 123})
61        self.assertTrue(result['test'](123))
62        self.assertFalse(result['test'](124))
63
64    def test_py_dict(self):
65        with self.assertRaises(RuntimeError):
66            afscgap.query_util.interpret_query_to_py({
67                'test': {'a': 1, 'b': '2'}
68            })
69
70    def test_py_limit_lower_bound(self):
71        result = afscgap.query_util.interpret_query_to_py({'test': (1, None)})
72        self.assertTrue(result['test'](123))
73        self.assertFalse(result['test'](0))
74
75    def test_py_limit_upper_bound(self):
76        result = afscgap.query_util.interpret_query_to_py({'test': (None, 1)})
77        self.assertTrue(result['test'](0))
78        self.assertFalse(result['test'](2))
79
80    def test_py_limit_range(self):
81        result = afscgap.query_util.interpret_query_to_py({'test': (1, 2)})
82        self.assertTrue(result['test'](1.5))
83        self.assertFalse(result['test'](3))

A class whose instances are single test cases.

By default, the test code itself should be placed in a method named 'runTest'.

If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.

Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.

If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.

When subclassing TestCase, you can set these attributes:

  • failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
  • longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
  • maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
def test_ords_none(self):
 9    def test_ords_none(self):
10        result = afscgap.query_util.interpret_query_to_ords({'test': None})
11        self.assertIsNone(result['test'])
def test_ords_str(self):
13    def test_ords_str(self):
14        result = afscgap.query_util.interpret_query_to_ords({'test': 'a'})
15        self.assertEquals(result['test'], 'a')
def test_ords_float(self):
17    def test_ords_float(self):
18        result = afscgap.query_util.interpret_query_to_ords({'test': 1.23})
19        self.assertAlmostEquals(result['test'], 1.23)
def test_ords_int(self):
21    def test_ords_int(self):
22        result = afscgap.query_util.interpret_query_to_ords({'test': 123})
23        self.assertAlmostEquals(result['test'], 123)
def test_ords_dict(self):
25    def test_ords_dict(self):
26        result = afscgap.query_util.interpret_query_to_ords({
27            'test': {'a': 1, 'b': '2'}
28        })
29        self.assertEquals(result['test']['a'], 1)
30        self.assertEquals(result['test']['b'], '2')
def test_ords_limit_lower_bound(self):
32    def test_ords_limit_lower_bound(self):
33        result = afscgap.query_util.interpret_query_to_ords({'test': (1, None)})
34        self.assertEquals(result['test']['$gte'], 1)
def test_ords_limit_upper_bound(self):
36    def test_ords_limit_upper_bound(self):
37        result = afscgap.query_util.interpret_query_to_ords({'test': (None, 1)})
38        self.assertEquals(result['test']['$lte'], 1)
def test_ords_limit_range(self):
40    def test_ords_limit_range(self):
41        result = afscgap.query_util.interpret_query_to_ords({'test': (1, 2)})
42        self.assertEquals(result['test']['$between'][0], 1)
43        self.assertEquals(result['test']['$between'][1], 2)
def test_py_none(self):
45    def test_py_none(self):
46        result = afscgap.query_util.interpret_query_to_py({'test': None})
47        self.assertIsNone(result['test'])
def test_py_str(self):
49    def test_py_str(self):
50        result = afscgap.query_util.interpret_query_to_py({'test': 'a'})
51        self.assertTrue(result['test']('a'))
52        self.assertFalse(result['test']('b'))
def test_py_float(self):
54    def test_py_float(self):
55        result = afscgap.query_util.interpret_query_to_py({'test': 1.23})
56        self.assertTrue(result['test'](1.23))
57        self.assertFalse(result['test'](1.24))
def test_py_int(self):
59    def test_py_int(self):
60        result = afscgap.query_util.interpret_query_to_py({'test': 123})
61        self.assertTrue(result['test'](123))
62        self.assertFalse(result['test'](124))
def test_py_dict(self):
64    def test_py_dict(self):
65        with self.assertRaises(RuntimeError):
66            afscgap.query_util.interpret_query_to_py({
67                'test': {'a': 1, 'b': '2'}
68            })
def test_py_limit_lower_bound(self):
70    def test_py_limit_lower_bound(self):
71        result = afscgap.query_util.interpret_query_to_py({'test': (1, None)})
72        self.assertTrue(result['test'](123))
73        self.assertFalse(result['test'](0))
def test_py_limit_upper_bound(self):
75    def test_py_limit_upper_bound(self):
76        result = afscgap.query_util.interpret_query_to_py({'test': (None, 1)})
77        self.assertTrue(result['test'](0))
78        self.assertFalse(result['test'](2))
def test_py_limit_range(self):
80    def test_py_limit_range(self):
81        result = afscgap.query_util.interpret_query_to_py({'test': (1, 2)})
82        self.assertTrue(result['test'](1.5))
83        self.assertFalse(result['test'](3))
Inherited Members
unittest.case.TestCase
TestCase
failureException
longMessage
maxDiff
addTypeEqualityFunc
addCleanup
enterContext
addClassCleanup
enterClassContext
setUp
tearDown
setUpClass
tearDownClass
countTestCases
defaultTestResult
shortDescription
id
subTest
run
doCleanups
doClassCleanups
debug
skipTest
fail
assertFalse
assertTrue
assertRaises
assertWarns
assertLogs
assertNoLogs
assertEqual
assertNotEqual
assertAlmostEqual
assertNotAlmostEqual
assertSequenceEqual
assertListEqual
assertTupleEqual
assertSetEqual
assertIn
assertNotIn
assertIs
assertIsNot
assertDictEqual
assertDictContainsSubset
assertCountEqual
assertMultiLineEqual
assertLess
assertLessEqual
assertGreater
assertGreaterEqual
assertIsNone
assertIsNotNone
assertIsInstance
assertNotIsInstance
assertRaisesRegex
assertWarnsRegex
assertRegex
assertNotRegex
failUnlessRaises
failIf
assertRaisesRegexp
assertRegexpMatches
assertNotRegexpMatches
failUnlessEqual
assertEquals
failIfEqual
assertNotEquals
failUnlessAlmostEqual
assertAlmostEquals
failIfAlmostEqual
assertNotAlmostEquals
failUnless
assert_