Пример #1
0
    def test_namedtuples(self):
        ntup = namedtuple('ntup', ['col1', 'col2'])

        records = [ntup(1, 'a'), ntup(2, 'b')]
        reader = get_reader(records)

        expected = [('col1', 'col2'), (1, 'a'), (2, 'b')]
        self.assertEqual(list(reader), expected)
Пример #2
0
 def test_three_args_namedtuples(self):
     ntup = collections.namedtuple('ntup', ['A', 'B'])
     records = [
         ntup('x', 1),
         ntup('y', 2),
     ]
     load_data(self.cursor, 'testtable', records)  # <- Three args.
     self.cursor.execute('SELECT A, B FROM testtable')
     self.assertEqual(self.cursor.fetchall(), [('x', 1), ('y', 2)])
Пример #3
0
 def test_select_dict_with_namedtuple_keys(self):
     namedtup = collections.namedtuple('namedtup', ['x', 'y'])
     result = self.source._select({namedtup('label1', 'label2'): ['value']})
     expected = {
         namedtup(x='a', y='x'): ['17', '13'],
         namedtup(x='a', y='y'): ['20'],
         namedtup(x='a', y='z'): ['15'],
         namedtup(x='b', y='x'): ['25'],
         namedtup(x='b', y='y'): ['40'],
         namedtup(x='b', y='z'): ['5'],
     }
     self.assertEqual(result.fetch(), expected)
Пример #4
0
 def setUp(self):
     ntup = collections.namedtuple('ntup', ('cls', 'args', 'priority'))
     self.allowances = [
         ntup(cls=allowed_missing,   args=tuple(),                  priority=100),
         ntup(cls=allowed_extra,     args=tuple(),                  priority=100),
         ntup(cls=allowed_invalid,   args=tuple(),                  priority=100),
         ntup(cls=allowed_deviation, args=(5,),                     priority=100),
         ntup(cls=allowed_percent,   args=(0.05,),                  priority=100),
         ntup(cls=allowed_keys,      args=(lambda args: True,),     priority=100),
         ntup(cls=allowed_args,      args=(lambda *args: True,),    priority=100),
         ntup(cls=allowed_specific,  args=({'X': [Invalid('A')]},), priority=200),
         ntup(cls=allowed_limit,     args=(4,),                     priority=300),
     ]
Пример #5
0
 def test_select_list_of_namedtuples(self):
     namedtup = collections.namedtuple('namedtup', ['label1', 'label2'])
     result = self.source._select([namedtup('label1', 'label2')])
     expected = [
         namedtup(label1='a', label2='x'),
         namedtup(label1='a', label2='x'),
         namedtup(label1='a', label2='y'),
         namedtup(label1='a', label2='z'),
         namedtup(label1='b', label2='z'),
         namedtup(label1='b', label2='y'),
         namedtup(label1='b', label2='x')
     ]
     self.assertEqual(result.fetch(), expected)
Пример #6
0
 def setUp(self):
     ntup = namedtuple('ntup', ('cls', 'args', 'scope'))
     self.acceptances = [
         ntup(cls=AcceptedDifferences, args=(Invalid('A'),),        scope=set(['element'])),
         ntup(cls=AcceptedDifferences, args=([Invalid('A')],),      scope=set(['group'])),
         ntup(cls=AcceptedDifferences, args=({'X': [Invalid('A')]},), scope=set(['group'])),
         ntup(cls=AcceptedDifferences, args=([Invalid('A')], None, 'whole'), scope=set(['whole'])),
         ntup(cls=AcceptedKeys,      args=(lambda args: True,),     scope=set(['element'])),
         ntup(cls=AcceptedArgs,      args=(lambda *args: True,),    scope=set(['element'])),
         ntup(cls=AcceptedTolerance, args=(10,),                    scope=set(['element'])),
         ntup(cls=AcceptedPercent,   args=(0.05,),                  scope=set(['element'])),
         ntup(cls=AcceptedFuzzy,     args=tuple(),                  scope=set(['element'])),
         ntup(cls=AcceptedCount,     args=(4,),                     scope=set(['whole'])),
     ]
Пример #7
0
 def setUp(self):
     ntup = namedtuple('ntup', ('cls', 'args', 'priority'))
     self.acceptances = [
         ntup(cls=AcceptedFuzzy, args=tuple(), priority=4),
         ntup(cls=AcceptedPercent, args=(0.05, ), priority=4),
         ntup(cls=AcceptedKeys, args=(lambda args: True, ), priority=4),
         ntup(cls=AcceptedArgs, args=(lambda *args: True, ), priority=4),
         ntup(cls=AcceptedCount, args=(4, ), priority=256),
         ntup(cls=AcceptedDifferences, args=(Invalid('A'), ), priority=4),
         ntup(cls=AcceptedDifferences, args=([Invalid('A')], ),
              priority=32),
         ntup(cls=AcceptedDifferences,
              args=({
                  'X': [Invalid('A')]
              }, ),
              priority=32),
         ntup(cls=AcceptedDifferences,
              args=([Invalid('A')], None, 'whole'),
              priority=256),
     ]