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

LanguageDefinitionTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_external_coalang() 0 8 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 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