def test_invalid_values(self):
        cf = JSONConfigParser()

        try:
            cf.read_string((
                '[section]\n'
                'unmatched = [1,2,3}'
            ))
        except ParseError as e:
            self.assertEqual(e.lineno, 2)

            # check that nothing was added
            self.assertEqual(sum(1 for _ in cf.sections()), 0)
        else:
            self.fail()

        try:
            cf.read_string((
                '[section]\n'
                'unterminated = "something\n'
            ))
        except ParseError as e:
            self.assertEqual(e.lineno, 2)

            # check that nothing was added
            self.assertEqual(sum(1 for _ in cf.sections()), 0)
        else:
            self.fail()
Ejemplo n.º 2
0
    def test_invalid_values(self):
        cf = JSONConfigParser()

        try:
            cf.read_string((
                '[section]\n'
                'unmatched = [1,2,3}'
            ))
        except ParseError as e:
            self.assertEqual(e.lineno, 2)

            # check that nothing was added
            self.assertEqual(sum(1 for _ in cf.sections()), 0)
        else:  # pragma: no cover
            self.fail()

        try:
            cf.read_string((
                '[section]\n'
                'unterminated = "something\n'
            ))
        except ParseError as e:
            self.assertEqual(e.lineno, 2)

            # check that nothing was added
            self.assertEqual(sum(1 for _ in cf.sections()), 0)
        else:  # pragma: no cover
            self.fail()
    def test_invalid_section(self):
        cf = JSONConfigParser()

        try:
            cf.read_string((
                '[valid]\n'
                'irrelevant = "meh"\n'
                '[]'
            ))
        except ParseError as e:
            self.assertEqual(e.lineno, 3)

            # check that nothing was added
            self.assertEqual(sum(1 for _ in cf.sections()), 0)
        else:
            self.fail()

        try:
            cf.read_string((
                '[nooooooooooooooooooo'
            ))
        except ParseError as e:
            self.assertEqual(e.lineno, 1)

            # check that nothing was added
            self.assertEqual(sum(1 for _ in cf.sections()), 0)
        else:
            self.fail()
Ejemplo n.º 4
0
    def test_invalid_section(self):
        cf = JSONConfigParser()

        try:
            cf.read_string((
                '[valid]\n'
                'irrelevant = "meh"\n'
                '[]'
            ))
        except ParseError as e:
            self.assertEqual(e.lineno, 3)

            # check that nothing was added
            self.assertEqual(sum(1 for _ in cf.sections()), 0)
        else:  # pragma: no cover
            self.fail()

        try:
            cf.read_string((
                '[nooooooooooooooooooo'
            ))
        except ParseError as e:
            self.assertEqual(e.lineno, 1)

            # check that nothing was added
            self.assertEqual(sum(1 for _ in cf.sections()), 0)
        else:  # pragma: no cover
            self.fail()