aboutsummaryrefslogtreecommitdiff
path: root/gazelle/python/parse_test.py
blob: 3ebded44b3fd6249e946ee1f6efc36fb93ccf37c (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
import unittest
import parse

class TestParse(unittest.TestCase):
    def test_not_has_main(self):
        content = "a = 1\nb = 2"
        self.assertFalse(parse.parse_main(content))

    def test_has_main_in_function(self):
        content = """
def foo():
    if __name__ == "__main__":
        a = 3
"""
        self.assertFalse(parse.parse_main(content))

    def test_has_main(self):
        content = """
import unittest

from lib import main


class ExampleTest(unittest.TestCase):
    def test_main(self):
        self.assertEqual(
            "",
            main([["A", 1], ["B", 2]]),
        )


if __name__ == "__main__":
    unittest.main()
"""
        self.assertTrue(parse.parse_main(content))


if __name__ == "__main__":
    unittest.main()