afscgap.test.test_convert

  1import unittest
  2import unittest.mock
  3
  4import afscgap.convert
  5
  6
  7class ConvertTests(unittest.TestCase):
  8
  9    def test_convert_to_iso8601_success(self):
 10        result = afscgap.convert.convert_to_iso8601('07/16/2021 11:30:22')
 11        self.assertEqual(result, '2021-07-16T11:30:22')
 12
 13    def test_convert_to_iso8601_fail(self):
 14        result = afscgap.convert.convert_to_iso8601('test')
 15        self.assertEqual(result, 'test')
 16
 17    def test_iso8601_regex_not_found(self):
 18        self.assertIsNone(
 19            afscgap.convert.ISO_8601_REGEX.match('07/16/2021 11:30:22')
 20        )
 21
 22    def test_iso8601_regex_found(self):
 23        self.assertIsNotNone(
 24            afscgap.convert.ISO_8601_REGEX.match('2021-07-16T11:30:22')
 25        )
 26
 27    def test_convert_from_iso8601_match_string(self):
 28        result = afscgap.convert.convert_from_iso8601_str(
 29            '2021-07-16T11:30:22'
 30        )
 31        self.assertEquals(result, '07/16/2021 11:30:22')
 32
 33    def test_convert_from_iso8601_match_string_with_tz(self):
 34        result = afscgap.convert.convert_from_iso8601_str(
 35            '2021-07-16T11:30:22Z'
 36        )
 37        self.assertEquals(result, '07/16/2021 11:30:22')
 38
 39    def test_convert_from_iso8601_match_dict(self):
 40        test_dict = {
 41            'a': '2021-07-16T11:30:22',
 42            'b': 'test2',
 43            'c': 3
 44        }
 45        result = afscgap.convert.convert_from_iso8601(test_dict)
 46        self.assertEquals(result['a'], '07/16/2021 11:30:22')
 47        self.assertEquals(result['b'], 'test2')
 48        self.assertEquals(result['c'], 3)
 49
 50    def test_convert_from_iso8601_match_none(self):
 51        result = afscgap.convert.convert_from_iso8601(3)
 52        self.assertEquals(result, 3)
 53
 54    def test_is_iso8601_success(self):
 55        self.assertTrue(afscgap.convert.is_iso8601('2021-07-16T11:30:22'))
 56
 57    def test_is_iso8601_fail(self):
 58        self.assertFalse(afscgap.convert.is_iso8601('07/16/2021 11:30:22'))
 59
 60    def test_convert_area(self):
 61        self.assertAlmostEquals(
 62            afscgap.convert.convert_area(123, 'm2'),
 63            1230000
 64        )
 65
 66    def test_unconvert_area(self):
 67        self.assertAlmostEquals(
 68            afscgap.convert.unconvert_area(1.23, 'km2'),
 69            123
 70        )
 71
 72    def test_convert_degrees(self):
 73        self.assertAlmostEquals(
 74            afscgap.convert.convert_degrees(123, 'dd'),
 75            123
 76        )
 77
 78    def test_unconvert_degrees(self):
 79        self.assertAlmostEquals(
 80            afscgap.convert.unconvert_degrees(123, 'dd'),
 81            123
 82        )
 83
 84    def test_convert_distance(self):
 85        self.assertAlmostEquals(
 86            afscgap.convert.convert_distance(123, 'km'),
 87            0.123
 88        )
 89
 90    def test_unconvert_distance(self):
 91        self.assertAlmostEquals(
 92            afscgap.convert.unconvert_distance(123, 'km'),
 93            123000
 94        )
 95
 96    def test_convert_temperature(self):
 97        self.assertAlmostEquals(
 98            afscgap.convert.convert_temperature(12, 'f'),
 99            53.6
100        )
101
102    def test_unconvert_temperature(self):
103        self.assertAlmostEquals(
104            afscgap.convert.unconvert_temperature(12, 'f'),
105            -11.111111111
106        )
107
108    def test_convert_time(self):
109        self.assertAlmostEquals(
110            afscgap.convert.convert_time(123, 'day'),
111            5.125
112        )
113
114    def test_unconvert_time(self):
115        self.assertAlmostEquals(
116            afscgap.convert.unconvert_time(123, 'min'),
117            2.05
118        )
119
120    def test_convert_weight(self):
121        self.assertAlmostEquals(
122            afscgap.convert.convert_weight(12, 'g'),
123            12000
124        )
125
126    def test_unconvert_weight(self):
127        self.assertAlmostEquals(
128            afscgap.convert.unconvert_weight(12, 'g'),
129            0.012
130        )
class ConvertTests(unittest.case.TestCase):
  8class ConvertTests(unittest.TestCase):
  9
 10    def test_convert_to_iso8601_success(self):
 11        result = afscgap.convert.convert_to_iso8601('07/16/2021 11:30:22')
 12        self.assertEqual(result, '2021-07-16T11:30:22')
 13
 14    def test_convert_to_iso8601_fail(self):
 15        result = afscgap.convert.convert_to_iso8601('test')
 16        self.assertEqual(result, 'test')
 17
 18    def test_iso8601_regex_not_found(self):
 19        self.assertIsNone(
 20            afscgap.convert.ISO_8601_REGEX.match('07/16/2021 11:30:22')
 21        )
 22
 23    def test_iso8601_regex_found(self):
 24        self.assertIsNotNone(
 25            afscgap.convert.ISO_8601_REGEX.match('2021-07-16T11:30:22')
 26        )
 27
 28    def test_convert_from_iso8601_match_string(self):
 29        result = afscgap.convert.convert_from_iso8601_str(
 30            '2021-07-16T11:30:22'
 31        )
 32        self.assertEquals(result, '07/16/2021 11:30:22')
 33
 34    def test_convert_from_iso8601_match_string_with_tz(self):
 35        result = afscgap.convert.convert_from_iso8601_str(
 36            '2021-07-16T11:30:22Z'
 37        )
 38        self.assertEquals(result, '07/16/2021 11:30:22')
 39
 40    def test_convert_from_iso8601_match_dict(self):
 41        test_dict = {
 42            'a': '2021-07-16T11:30:22',
 43            'b': 'test2',
 44            'c': 3
 45        }
 46        result = afscgap.convert.convert_from_iso8601(test_dict)
 47        self.assertEquals(result['a'], '07/16/2021 11:30:22')
 48        self.assertEquals(result['b'], 'test2')
 49        self.assertEquals(result['c'], 3)
 50
 51    def test_convert_from_iso8601_match_none(self):
 52        result = afscgap.convert.convert_from_iso8601(3)
 53        self.assertEquals(result, 3)
 54
 55    def test_is_iso8601_success(self):
 56        self.assertTrue(afscgap.convert.is_iso8601('2021-07-16T11:30:22'))
 57
 58    def test_is_iso8601_fail(self):
 59        self.assertFalse(afscgap.convert.is_iso8601('07/16/2021 11:30:22'))
 60
 61    def test_convert_area(self):
 62        self.assertAlmostEquals(
 63            afscgap.convert.convert_area(123, 'm2'),
 64            1230000
 65        )
 66
 67    def test_unconvert_area(self):
 68        self.assertAlmostEquals(
 69            afscgap.convert.unconvert_area(1.23, 'km2'),
 70            123
 71        )
 72
 73    def test_convert_degrees(self):
 74        self.assertAlmostEquals(
 75            afscgap.convert.convert_degrees(123, 'dd'),
 76            123
 77        )
 78
 79    def test_unconvert_degrees(self):
 80        self.assertAlmostEquals(
 81            afscgap.convert.unconvert_degrees(123, 'dd'),
 82            123
 83        )
 84
 85    def test_convert_distance(self):
 86        self.assertAlmostEquals(
 87            afscgap.convert.convert_distance(123, 'km'),
 88            0.123
 89        )
 90
 91    def test_unconvert_distance(self):
 92        self.assertAlmostEquals(
 93            afscgap.convert.unconvert_distance(123, 'km'),
 94            123000
 95        )
 96
 97    def test_convert_temperature(self):
 98        self.assertAlmostEquals(
 99            afscgap.convert.convert_temperature(12, 'f'),
100            53.6
101        )
102
103    def test_unconvert_temperature(self):
104        self.assertAlmostEquals(
105            afscgap.convert.unconvert_temperature(12, 'f'),
106            -11.111111111
107        )
108
109    def test_convert_time(self):
110        self.assertAlmostEquals(
111            afscgap.convert.convert_time(123, 'day'),
112            5.125
113        )
114
115    def test_unconvert_time(self):
116        self.assertAlmostEquals(
117            afscgap.convert.unconvert_time(123, 'min'),
118            2.05
119        )
120
121    def test_convert_weight(self):
122        self.assertAlmostEquals(
123            afscgap.convert.convert_weight(12, 'g'),
124            12000
125        )
126
127    def test_unconvert_weight(self):
128        self.assertAlmostEquals(
129            afscgap.convert.unconvert_weight(12, 'g'),
130            0.012
131        )

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_convert_to_iso8601_success(self):
10    def test_convert_to_iso8601_success(self):
11        result = afscgap.convert.convert_to_iso8601('07/16/2021 11:30:22')
12        self.assertEqual(result, '2021-07-16T11:30:22')
def test_convert_to_iso8601_fail(self):
14    def test_convert_to_iso8601_fail(self):
15        result = afscgap.convert.convert_to_iso8601('test')
16        self.assertEqual(result, 'test')
def test_iso8601_regex_not_found(self):
18    def test_iso8601_regex_not_found(self):
19        self.assertIsNone(
20            afscgap.convert.ISO_8601_REGEX.match('07/16/2021 11:30:22')
21        )
def test_iso8601_regex_found(self):
23    def test_iso8601_regex_found(self):
24        self.assertIsNotNone(
25            afscgap.convert.ISO_8601_REGEX.match('2021-07-16T11:30:22')
26        )
def test_convert_from_iso8601_match_string(self):
28    def test_convert_from_iso8601_match_string(self):
29        result = afscgap.convert.convert_from_iso8601_str(
30            '2021-07-16T11:30:22'
31        )
32        self.assertEquals(result, '07/16/2021 11:30:22')
def test_convert_from_iso8601_match_string_with_tz(self):
34    def test_convert_from_iso8601_match_string_with_tz(self):
35        result = afscgap.convert.convert_from_iso8601_str(
36            '2021-07-16T11:30:22Z'
37        )
38        self.assertEquals(result, '07/16/2021 11:30:22')
def test_convert_from_iso8601_match_dict(self):
40    def test_convert_from_iso8601_match_dict(self):
41        test_dict = {
42            'a': '2021-07-16T11:30:22',
43            'b': 'test2',
44            'c': 3
45        }
46        result = afscgap.convert.convert_from_iso8601(test_dict)
47        self.assertEquals(result['a'], '07/16/2021 11:30:22')
48        self.assertEquals(result['b'], 'test2')
49        self.assertEquals(result['c'], 3)
def test_convert_from_iso8601_match_none(self):
51    def test_convert_from_iso8601_match_none(self):
52        result = afscgap.convert.convert_from_iso8601(3)
53        self.assertEquals(result, 3)
def test_is_iso8601_success(self):
55    def test_is_iso8601_success(self):
56        self.assertTrue(afscgap.convert.is_iso8601('2021-07-16T11:30:22'))
def test_is_iso8601_fail(self):
58    def test_is_iso8601_fail(self):
59        self.assertFalse(afscgap.convert.is_iso8601('07/16/2021 11:30:22'))
def test_convert_area(self):
61    def test_convert_area(self):
62        self.assertAlmostEquals(
63            afscgap.convert.convert_area(123, 'm2'),
64            1230000
65        )
def test_unconvert_area(self):
67    def test_unconvert_area(self):
68        self.assertAlmostEquals(
69            afscgap.convert.unconvert_area(1.23, 'km2'),
70            123
71        )
def test_convert_degrees(self):
73    def test_convert_degrees(self):
74        self.assertAlmostEquals(
75            afscgap.convert.convert_degrees(123, 'dd'),
76            123
77        )
def test_unconvert_degrees(self):
79    def test_unconvert_degrees(self):
80        self.assertAlmostEquals(
81            afscgap.convert.unconvert_degrees(123, 'dd'),
82            123
83        )
def test_convert_distance(self):
85    def test_convert_distance(self):
86        self.assertAlmostEquals(
87            afscgap.convert.convert_distance(123, 'km'),
88            0.123
89        )
def test_unconvert_distance(self):
91    def test_unconvert_distance(self):
92        self.assertAlmostEquals(
93            afscgap.convert.unconvert_distance(123, 'km'),
94            123000
95        )
def test_convert_temperature(self):
 97    def test_convert_temperature(self):
 98        self.assertAlmostEquals(
 99            afscgap.convert.convert_temperature(12, 'f'),
100            53.6
101        )
def test_unconvert_temperature(self):
103    def test_unconvert_temperature(self):
104        self.assertAlmostEquals(
105            afscgap.convert.unconvert_temperature(12, 'f'),
106            -11.111111111
107        )
def test_convert_time(self):
109    def test_convert_time(self):
110        self.assertAlmostEquals(
111            afscgap.convert.convert_time(123, 'day'),
112            5.125
113        )
def test_unconvert_time(self):
115    def test_unconvert_time(self):
116        self.assertAlmostEquals(
117            afscgap.convert.unconvert_time(123, 'min'),
118            2.05
119        )
def test_convert_weight(self):
121    def test_convert_weight(self):
122        self.assertAlmostEquals(
123            afscgap.convert.convert_weight(12, 'g'),
124            12000
125        )
def test_unconvert_weight(self):
127    def test_unconvert_weight(self):
128        self.assertAlmostEquals(
129            afscgap.convert.unconvert_weight(12, 'g'),
130            0.012
131        )
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_