Exemplo n.º 1
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)
Exemplo n.º 2
0
    def test_rules_1(self):

        result = mapping_rule.apply(self.rules, self.data)
        expected = {
            'cpu': '8-core',
            'ram': 'inconnu',
            'serialnumber': 'inconnu'
        }
        self.assertDictEqual(result, expected)
Exemplo n.º 3
0
 def test_rules_2(self):
     self.data['new_field'] = 'foo'
     result = mapping_rule.apply(self.rules, self.data)
     expected = {
         'cpu': '8-core',
         'ram': 'inconnu',
         'serialnumber': 'inconnu',
         'new_field': 'foo'
     }
     self.assertDictEqual(result, expected)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 6
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)