Issue #18260.
(self)
| 1564 | self.assertEqual(parser["Foo Bar"]["foo"], "newbar") |
| 1565 | |
| 1566 | def test_source_as_bytes(self): |
| 1567 | """Issue #18260.""" |
| 1568 | lines = textwrap.dedent(""" |
| 1569 | [badbad] |
| 1570 | [badbad]""").strip().split('\n') |
| 1571 | parser = configparser.ConfigParser() |
| 1572 | with self.assertRaises(configparser.DuplicateSectionError) as dse: |
| 1573 | parser.read_file(lines, source=b"badbad") |
| 1574 | self.assertEqual( |
| 1575 | str(dse.exception), |
| 1576 | "While reading from b'badbad' [line 2]: section 'badbad' " |
| 1577 | "already exists" |
| 1578 | ) |
| 1579 | lines = textwrap.dedent(""" |
| 1580 | [badbad] |
| 1581 | bad = bad |
| 1582 | bad = bad""").strip().split('\n') |
| 1583 | parser = configparser.ConfigParser() |
| 1584 | with self.assertRaises(configparser.DuplicateOptionError) as dse: |
| 1585 | parser.read_file(lines, source=b"badbad") |
| 1586 | self.assertEqual( |
| 1587 | str(dse.exception), |
| 1588 | "While reading from b'badbad' [line 3]: option 'bad' in section " |
| 1589 | "'badbad' already exists" |
| 1590 | ) |
| 1591 | lines = textwrap.dedent(""" |
| 1592 | [badbad] |
| 1593 | = bad""").strip().split('\n') |
| 1594 | parser = configparser.ConfigParser() |
| 1595 | with self.assertRaises(configparser.ParsingError) as dse: |
| 1596 | parser.read_file(lines, source=b"badbad") |
| 1597 | self.assertEqual( |
| 1598 | str(dse.exception), |
| 1599 | "Source contains parsing errors: b'badbad'\n\t[line 2]: '= bad'" |
| 1600 | ) |
| 1601 | lines = textwrap.dedent(""" |
| 1602 | [badbad |
| 1603 | bad = bad""").strip().split('\n') |
| 1604 | parser = configparser.ConfigParser() |
| 1605 | with self.assertRaises(configparser.MissingSectionHeaderError) as dse: |
| 1606 | parser.read_file(lines, source=b"badbad") |
| 1607 | self.assertEqual( |
| 1608 | str(dse.exception), |
| 1609 | "File contains no section headers.\nfile: b'badbad', line: 1\n" |
| 1610 | "'[badbad'" |
| 1611 | ) |
| 1612 | |
| 1613 | def test_keys_without_value_with_extra_whitespace(self): |
| 1614 | lines = [ |
nothing calls this directly
no test coverage detected