Completed
Pull Request — master (#31)
by Philip
01:20
created

TestDotEnv.tearDown()   A

Complexity

Conditions 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
1
import os
2
import textwrap
3
import unittest
4
from tempfile import NamedTemporaryFile
5
6
from foil.dotenv import read_dotenv
7
8
9
def mock_dotenv():
10
    return textwrap.dedent("""\
11
SECRET=quiet
12
# comment this
13
forgot equals
14
DB='drawer'""")
15
16
17
class TestDotEnv(unittest.TestCase):
18
19
    @classmethod
20
    def setUpClass(cls):
21
        with NamedTemporaryFile(suffix='.env', delete=False) as tmp:
22
            with open(tmp.name, 'w', encoding='UTF-8') as file:
23
                file.write(mock_dotenv())
24
            cls.path = tmp.name
25
26
    def test_read_dotenv(self):
27
        expected = [('SECRET', 'quiet'), ('DB', 'drawer')]
28
        result = list(read_dotenv(self.path))
29
30
        self.assertEqual(expected, result)
31
32
    @classmethod
33
    def tearDown(cls):
34
        if os.path.exists(cls.path):
35
            os.unlink(cls.path)
36