def test_named_tuple_colname_substitution(self):
     colnames = ("func(abc)", "[applied]", "func(func(abc))", "foo_bar", "foo_bar_")
     rows = [(1, 2, 3, 4, 5)]
     result = named_tuple_factory(colnames, rows)[0]
     self.assertEqual(result[0], result.func_abc)
     self.assertEqual(result[1], result.applied)
     self.assertEqual(result[2], result.func_func_abc)
     self.assertEqual(result[3], result.foo_bar)
     self.assertEqual(result[4], result.foo_bar_)
Example #2
0
 def test_named_tuple_colname_substitution(self):
     colnames = ("func(abc)", "[applied]", "func(func(abc))", "foo_bar", "foo_bar_")
     rows = [(1, 2, 3, 4, 5)]
     result = named_tuple_factory(colnames, rows)[0]
     self.assertEqual(result[0], result.func_abc)
     self.assertEqual(result[1], result.applied)
     self.assertEqual(result[2], result.func_func_abc)
     self.assertEqual(result[3], result.foo_bar)
     self.assertEqual(result[4], result.foo_bar_)
Example #3
0
    def test_creation_warning_on_long_column_list(self):
        """
        Reproduces the failure described in PYTHON-893

        @since 3.15
        @jira_ticket PYTHON-893
        @expected_result creation fails on Python > 3 and < 3.7

        @test_category row_factory
        """
        if not NAMEDTUPLE_CREATION_BUG:
            named_tuple_factory(self.long_colnames, self.long_rows)
            return

        with warnings.catch_warnings(record=True) as w:
            rows = named_tuple_factory(self.long_colnames, self.long_rows)
        self.assertEqual(len(w), 1)
        warning = w[0]
        self.assertIn('pseudo_namedtuple_factory', str(warning))
        self.assertIn('3.7', str(warning))

        for r in rows:
            self.assertEqual(r.col0, self.long_rows[0][0])
Example #4
0
    def test_creation_no_warning_on_short_column_list(self):
        """
        Tests that normal namedtuple row creation still works after PYTHON-893 fix

        @since 3.15
        @jira_ticket PYTHON-893
        @expected_result creates namedtuple-based Rows

        @test_category row_factory
        """
        with warnings.catch_warnings(record=True) as w:
            rows = named_tuple_factory(self.short_colnames, self.short_rows)
        self.assertEqual(len(w), 0)
        # check that this is a real namedtuple
        self.assertTrue(hasattr(rows[0], '_fields'))
        self.assertIsInstance(rows[0], tuple)