Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Test mock odoo module #76

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
omit = tests/*
setup.py
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
pip install tox codecov tox-gh-actions wheel
- name: Generate Report
run: |
pip install coverage
pip install .[test]
coverage run -m unittest
tox run
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # required
21 changes: 17 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
*.egg-info
*.pyc
.cache/
dist/
# Byte-compiled / optimized / DLL
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
build/
dist/
eggs/
.eggs/
*.egg-info/
*.egg

# Unit test / coverage reports
.tox
.coverage
.coverage.*
.cache/
8 changes: 5 additions & 3 deletions pytest_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ def _find_manifest_path(collection_path: Path) -> Path:
"""Try to locate an Odoo manifest file in the collection path."""
# check if collection_path is an addon directory
path = collection_path
level = 0
while level < 5 and not (path.parent / "__manifest__.py").is_file():
for _ in range(0, 5):
if (path.parent / "__manifest__.py").is_file():
break
path = path.parent
level += 1
else:
return None
return path.parent / "__manifest__.py"


Expand Down
Empty file added tests/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions tests/mock/odoo/odoo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from mock import MagicMock
registry = MagicMock()
tools = MagicMock()
2 changes: 2 additions & 0 deletions tests/mock/odoo/odoo/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from mock import MagicMock
common = MagicMock()
12 changes: 12 additions & 0 deletions tests/mock/odoo/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import find_packages, setup

setup(
name="odoo",
version="0.0.1",
packages=find_packages(),
package_dir={"odoo": "odoo"},
install_requires="mock"
)
39 changes: 39 additions & 0 deletions tests/test_pytest_odoo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from unittest import TestCase
import tempfile
from contextlib import contextmanager
from pytest_odoo import _find_manifest_path
from pathlib import Path

class TestPytestOdoo(TestCase):

@contextmanager
def fake_module(self):
directory = tempfile.TemporaryDirectory()
try:
module_path = Path(directory.name)
manifest_path = module_path / "__manifest__.py"
manifest_path.touch()
test_path = module_path / "tests" / "test_module.py"
test_path.parent.mkdir(parents=True, exist_ok=True)
test_path.touch()
yield (module_path, manifest_path, test_path,)
finally:
directory.cleanup()


def test_find_manifest_path_less_than_5_directories(self):
self.assertIsNone(_find_manifest_path(Path("/some/path")))

def test_find_manifest_path_from_test_module(self):
with self.fake_module() as (_, manifest_path, test_path):
self.assertEqual(_find_manifest_path(test_path), manifest_path)

def test_find_manifest_path_from_itself(self):
with self.fake_module() as (_, manifest_path, _):
self.assertEqual(_find_manifest_path(manifest_path), manifest_path)

def test_find_manifest_path_from_brother(self):
with self.fake_module() as (module_path, manifest_path, _):
test = module_path / "test_something.py"
test.touch()
self.assertEqual(_find_manifest_path(test), manifest_path)
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[testenv]
deps = pytest
pytest-cov
coverage
commands =
pip install tests/mock/odoo
pytest --cov=pytest_odoo . --cov-report=xml
Loading