Skip to content

Commit 3091554

Browse files
authored
Merge pull request #19 from intergral/coverage
chore(tests): add more tests and enforce test coverage
2 parents 945c18e + 404d520 commit 3091554

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1736
-53
lines changed

.flake8

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ per-file-ignores =
1212
# ignore unused imports in __init__ files
1313
*/__init__.py: F401
1414
# supress some docstring requirements in tests
15-
test/__init__.py: D104
16-
test/test_deep/__init__.py: D104
17-
test/test_deep/*/__init__.py: D104,D107
18-
test/test_deep/*/test_*.py: D101,D102,D107,D100,D105
19-
test/test_deep/test_*.py: D101,D102,D107,D100,D105
20-
test/test_deep/test_target.py: D102,D107,D103
15+
tests/unit_tests/*.py: D
16+
tests/unit_tests/**/*.py: D
2117
# these files are from OTEL so should use OTEL license.
2218
*/deep/api/types.py: NCF102
2319
*/deep/api/resource/__init__.py: NCF102
2420
*/deep/api/attributes/__init__.py: NCF102
21+
tests/unit_tests/api/attributes/*.py: NCF102,D
22+
tests/unit_tests/api/resource/*.py: NCF102,D
2523

2624
detailed-output = True
2725
copyright-regex =

.github/workflows/on_push.yaml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,26 @@ jobs:
2222
python -m pip install --upgrade pip
2323
pip install -r requirements.txt
2424
pip install -r dev-requirements.txt
25+
2526
- name: Flake8
26-
run: flake8
27+
run: make lint
28+
29+
coverage:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v3
33+
- name: Setup Python # Set Python version
34+
uses: actions/setup-python@v4
35+
with:
36+
python-version: 3.12
37+
# Install pip and pytest
38+
- name: Install dependencies
39+
run: |
40+
python -m pip install --upgrade pip
41+
pip install -r requirements.txt
42+
pip install -r dev-requirements.txt
43+
- run: |
44+
make coverage
2745
2846
tests:
2947

@@ -46,7 +64,7 @@ jobs:
4664
pip install -r dev-requirements.txt
4765
pip install .
4866
- name: Test with pytest
49-
run: pytest test --doctest-modules --junitxml=junit/test-results-${{ matrix.python-version }}.xml
67+
run: pytest tests/unit_tests --doctest-modules --junitxml=junit/test-results-${{ matrix.python-version }}.xml
5068
- name: Upload pytest test results
5169
uses: actions/upload-artifact@v3
5270
with:

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ endif
1616

1717
.PHONY: test
1818
test:
19-
pytest test
19+
pytest tests/unit_tests
20+
21+
.PHONY: coverage
22+
coverage:
23+
pytest tests/unit_tests --cov=deep --cov-report term --cov-fail-under=77 --cov-report html --cov-branch
2024

2125
.PHONY: lint
2226
lint:

deep-python-client.iml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
<sourceFolder url="file://$MODULE_DIR$/deep-extractor/src" isTestSource="false" />
88
<sourceFolder url="file://$MODULE_DIR$/examples/simple-app/src" isTestSource="false" />
99
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
10-
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
10+
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
1111
<excludeFolder url="file://$MODULE_DIR$/venv/lib/python3.10/site-packages/deep" />
1212
</content>
13-
<orderEntry type="jdk" jdkName="Python 3.10 (deep-python-client)" jdkType="Python SDK" />
13+
<orderEntry type="inheritedJdk" />
1414
<orderEntry type="sourceFolder" forTests="false" />
1515
</component>
16+
<component name="PackageRequirementsSettings">
17+
<option name="requirementsPath" value="requirements.txt, dev-requirments.txt" />
18+
</component>
1619
</module>

dev-requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ flake8-docstrings
1010
certifi>=2023.7.22 # not directly required, pinned by Snyk to avoid a vulnerability
1111
flake8-header-validator>=0.0.3
1212
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
13+
pytest-cov
14+
mockito
15+
opentelemetry-api
16+
opentelemetry-sdk

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ path = "src/deep/version.py"
4747
# read dependencies from reuirements.txt
4848
[tool.setuptools.dynamic]
4949
dependencies = {file = ["requirements.txt"]}
50+
51+
[tool.pytest.ini_options]
52+
pythonpath = [
53+
"./src",
54+
"./tests"
55+
]
56+
57+
[tool.coverage.report]
58+
exclude_lines = [
59+
"if TYPE_CHECKING:",
60+
"@abc.abstractmethod"
61+
]

src/deep/api/attributes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _clean_attribute_value(
4343

4444

4545
def _clean_attribute(
46-
key: str, value: types.AttributeValue, max_len: Optional[int]
46+
key: str, value: Union[types.AttributeValue, Sequence[types.AttributeValue]], max_len: Optional[int]
4747
) -> Optional[types.AttributeValue]:
4848
"""
4949
Check if attribute value is valid and cleans it if required.

src/deep/api/deep.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def shutdown(self):
6868
if not self.started:
6969
return
7070
self.task_handler.flush()
71+
self.poll.shutdown()
7172
self.started = False
7273

7374
def register_tracepoint(self, path: str, line: int, args: Dict[str, str] = None,

src/deep/api/plugin/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,26 @@ def __plugin_generator(configured):
3838
try:
3939
module, cls = plugin.rsplit(".", 1)
4040
yield getattr(import_module(module), cls)
41-
logging.debug('Did import default integration %s', plugin)
42-
except (DidNotEnable, SyntaxError) as e:
41+
logging.debug('Did import integration %s', plugin)
42+
except (DidNotEnable, Exception) as e:
4343
logging.debug(
44-
"Did not import default integration %s: %s", plugin, e
44+
"Did not import integration %s: %s", plugin, e
4545
)
4646

4747

48-
def load_plugins() -> 'Tuple[list[Plugin], BoundedAttributes]':
48+
def load_plugins(custom=None) -> 'Tuple[list[Plugin], BoundedAttributes]':
4949
"""
5050
Load all the deep plugins.
5151
5252
Attempt to load each plugin, if successful merge a attributes list of each plugin.
5353
5454
:return: the loaded plugins and attributes.
5555
"""
56+
if custom is None:
57+
custom = []
5658
bounded_attributes = BoundedAttributes(immutable=False)
5759
loaded = []
58-
for plugin in __plugin_generator(DEEP_PLUGINS):
60+
for plugin in __plugin_generator(DEEP_PLUGINS + custom):
5961
try:
6062
plugin_instance = plugin()
6163
if not plugin_instance.is_active():

0 commit comments

Comments
 (0)