|
| 1 | +from unittest import TestCase |
| 2 | +import tempfile |
| 3 | +from contextlib import contextmanager |
| 4 | +from pytest_odoo import _find_manifest_path |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +class TestPytestOdoo(TestCase): |
| 8 | + |
| 9 | + @contextmanager |
| 10 | + def fake_module(self): |
| 11 | + directory = tempfile.TemporaryDirectory() |
| 12 | + try: |
| 13 | + module_path = Path(directory.name) |
| 14 | + manifest_path = module_path / "__manifest__.py" |
| 15 | + manifest_path.touch() |
| 16 | + test_path = module_path / "tests" / "test_module.py" |
| 17 | + test_path.parent.mkdir(parents=True, exist_ok=True) |
| 18 | + test_path.touch() |
| 19 | + yield (module_path, manifest_path, test_path,) |
| 20 | + finally: |
| 21 | + directory.cleanup() |
| 22 | + |
| 23 | + |
| 24 | + def test_find_manifest_path_less_than_5_directories(self): |
| 25 | + self.assertIsNone(_find_manifest_path(Path("/some/path"))) |
| 26 | + |
| 27 | + def test_find_manifest_path_from_test_module(self): |
| 28 | + with self.fake_module() as (_, manifest_path, test_path): |
| 29 | + self.assertEqual(_find_manifest_path(test_path), manifest_path) |
| 30 | + |
| 31 | + def test_find_manifest_path_from_itself(self): |
| 32 | + with self.fake_module() as (_, manifest_path, _): |
| 33 | + self.assertEqual(_find_manifest_path(manifest_path), manifest_path) |
| 34 | + |
| 35 | + def test_find_manifest_path_from_brother(self): |
| 36 | + with self.fake_module() as (module_path, manifest_path, _): |
| 37 | + test = module_path / "test_something.py" |
| 38 | + test.touch() |
| 39 | + self.assertEqual(_find_manifest_path(test), manifest_path) |
0 commit comments