portfoliome /
foil
| 1 | import os |
||
|
0 ignored issues
–
show
|
|||
| 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 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.