summaryrefslogtreecommitdiff
path: root/testsuite/test_parser.py
blob: 1d9e1ac5fa67fd3c22c80b191762bcf0e0f86642 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import tempfile
import unittest

import pep8


def _process_file(contents):
    with tempfile.NamedTemporaryFile(delete=False) as f:
        f.write(contents)

    options, args = pep8.process_options(config_file=f.name)
    os.remove(f.name)

    return options, args


class ParserTestCase(unittest.TestCase):

    def test_vanilla_ignore_parsing(self):
        contents = b"""
[pep8]
ignore = E226,E24
        """
        options, args = _process_file(contents)

        self.assertEqual(options.ignore, ["E226", "E24"])

    def test_multiline_ignore_parsing(self):
        contents = b"""
[pep8]
ignore =
    E226,
    E24
        """

        options, args = _process_file(contents)

        self.assertEqual(options.ignore, ["E226", "E24"])

    def test_trailing_comma_ignore_parsing(self):
        contents = b"""
[pep8]
ignore = E226,
        """

        options, args = _process_file(contents)

        self.assertEqual(options.ignore, ["E226"])

    def test_multiline_trailing_comma_ignore_parsing(self):
        contents = b"""
[pep8]
ignore =
    E226,
    E24,
        """

        options, args = _process_file(contents)

        self.assertEqual(options.ignore, ["E226", "E24"])