Completed
Pull Request — master (#2295)
by Mischa
01:52
created

LanguageDefinitionTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 28
rs 10
c 2
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_external_coalang() 0 7 3
A test_nonexistant_file() 0 5 2
A test_key_contains() 0 4 1
A test_loading() 0 3 1
A setUp() 0 3 1
1
import unittest
2
3
from coalib.bearlib.languages.LanguageDefinition import LanguageDefinition
4
from coalib.settings.Section import Section
5
from coalib.settings.Setting import Setting
6
from coalib.misc.ContextManagers import make_temp
7
8
9
class LanguageDefinitionTest(unittest.TestCase):
10
11
    def setUp(self):
12
        self.section = Section("any")
13
        self.section.append(Setting("language", "CPP"))
14
15
    def test_nonexistant_file(self):
16
        self.section.append(Setting("language", "bullshit"))
17
18
        with self.assertRaises(FileNotFoundError):
19
            LanguageDefinition.from_section(self.section)
20
21
    def test_loading(self):
22
        uut = LanguageDefinition.from_section(self.section)
23
        self.assertEqual(list(uut["extensions"]), [".c", ".cpp", ".h", ".hpp"])
24
25
    def test_key_contains(self):
26
        uut = LanguageDefinition.from_section(self.section)
27
        self.assertIn("extensions", uut)
28
        self.assertNotIn("randomstuff", uut)
29
30
    def test_external_coalang(self):
31
        with make_temp() as coalang:
32
            with open(coalang, "w") as file:
33
                file.write('extensions = .lol, .ROFL')
34
            uut = LanguageDefinition("random_language", coalang_path=coalang)
35
            self.assertIn("extensions", uut)
36
            self.assertEqual(list(uut["extensions"]), [".lol", ".ROFL"])
37