Completed
Push — master ( e0da72...49d54f )
by Philip
25s
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
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
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