-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest_poetry.py
53 lines (41 loc) · 1.88 KB
/
test_poetry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import unittest
from flake8_requirements.checker import Flake8Checker
from flake8_requirements.checker import ModuleSet
from flake8_requirements.checker import memoize
try:
from unittest import mock
builtins_open = 'builtins.open'
except ImportError:
import mock
builtins_open = '__builtin__.open'
class PoetryTestCase(unittest.TestCase):
def setUp(self):
memoize.mem = {}
def test_get_pyproject_toml_poetry(self):
content = "[tool.poetry]\nname='x'\n[tool.poetry.tag]\nx=0\n"
with mock.patch(builtins_open, mock.mock_open(read_data=content)):
poetry = Flake8Checker.get_pyproject_toml_poetry()
self.assertDictEqual(poetry, {'name': "x", 'tag': {'x': 0}})
def test_1st_party(self):
content = "[tool.poetry]\nname='book'\n"
with mock.patch(builtins_open, mock.mock_open()) as m:
m.side_effect = (
IOError("No such file or directory: 'setup.py'"),
IOError("No such file or directory: 'setup.cfg'"),
mock.mock_open(read_data=content).return_value,
)
checker = Flake8Checker(None, None)
mods = checker.get_mods_1st_party()
self.assertEqual(mods, ModuleSet({"book": {}}))
def test_3rd_party(self):
content = "[tool.poetry.dependencies]\ntools='1.0'\n"
content += "[tool.poetry.dev-dependencies]\ndev-tools='1.0'\n"
with mock.patch(builtins_open, mock.mock_open()) as m:
m.side_effect = (
IOError("No such file or directory: 'setup.py'"),
IOError("No such file or directory: 'setup.cfg'"),
mock.mock_open(read_data=content).return_value,
)
checker = Flake8Checker(None, None)
mods = checker.get_mods_3rd_party()
self.assertEqual(mods, ModuleSet({"tools": {}, "dev_tools": {}}))