예제 #1
0
 def setUp(self) -> None:
     self.rules = (
         mapping_rule('cpu', default_if_false(bool, 'inconnu')),
         mapping_rule('ram', default_if_equal("#", 'inconnu')),
         mapping_rule('serialnumber', default_if_none('inconnu')),
     )
     self.data = {'cpu': '8-core', 'ram': "#", 'serialnumber': None}
예제 #2
0
    def test_rules_3(self):
        @set_field(None)
        def func(_, t):
            return ':'.join(str(e[1]) for e in t)

        rules = (mapping_rule('new_field', func, provide_all_values=True),
                 mapping_rule('constant', set_field(3.14)))
        result = mapping_rule.apply(rules, self.data)
        expected = {
            'cpu': '8-core',
            'ram': "#",
            'serialnumber': None,
            'new_field': '8-core:#:None',
            'constant': 3.14
        }
        self.assertDictEqual(expected, result)
예제 #3
0
 def test_rules_4(self):
     self.rules = (mapping_rule('ram', default_if_match(r"#", 'inconnu')), )
     result = mapping_rule.apply(self.rules, self.data)
     expected = {
         'cpu': '8-core',
         'ram': "inconnu",
         'serialnumber': None,
     }
     self.assertDictEqual(expected, result)
예제 #4
0
    def test_rules_9(self):
        data = {'a': 1, 'b': 2}

        def _add(_, t):
            d = dict(t)
            return d['a'] + d['b']

        rules = (mapping_rule('a+b', _add, provide_all_values=True), )
        result = mapping_rule.apply(rules, data)
        expected = {'a': 1, 'b': 2, 'a+b': 3}
        self.assertDictEqual(result, expected)
예제 #5
0
 def test_rules_8(self):
     self.data['f1'] = '-'
     self.rules = (mapping_rule('f1', default_if_not_equal('FOO', 'FOO')), )
     result = mapping_rule.apply(self.rules, self.data)
     expected = {
         'cpu': '8-core',
         'ram': "#",
         'serialnumber': None,
         'f1': 'FOO'
     }
     self.assertDictEqual(expected, result)