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

LanguageDefinitionTest.test_external_coalang()   A

Complexity

Conditions 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
1
import os.path
2
from tempfile import TemporaryDirectory
3
import unittest
4
5
from coalib.bearlib.languages.LanguageDefinition import LanguageDefinition
6
from coalib.settings.Section import Section
7
from coalib.settings.Setting import Setting
8
9
10
class LanguageDefinitionTest(unittest.TestCase):
11
12
    def setUp(self):
13
        self.section = Section("any")
14
        self.section.append(Setting("language", "CPP"))
15
16
    def test_nonexistant_file(self):
17
        self.section.append(Setting("language", "bullshit"))
18
19
        with self.assertRaises(FileNotFoundError):
20
            LanguageDefinition.from_section(self.section)
21
22
    def test_loading(self):
23
        uut = LanguageDefinition.from_section(self.section)
24
        self.assertEqual(list(uut["extensions"]), [".c", ".cpp", ".h", ".hpp"])
25
26
    def test_key_contains(self):
27
        uut = LanguageDefinition.from_section(self.section)
28
        self.assertIn("extensions", uut)
29
        self.assertNotIn("randomstuff", uut)
30
31
    def test_external_coalang(self):
32
        with TemporaryDirectory() as directory:
33
            coalang_file = os.path.join(directory, 'random_language.coalang')
34
            with open(coalang_file, 'w') as file:
35
                file.write('extensions = .lol, .ROFL')
36
            uut = LanguageDefinition("random_language", coalang_dir=directory)
37
            self.assertIn("extensions", uut)
38
            self.assertEqual(list(uut["extensions"]), [".lol", ".ROFL"])
39