Skip to content
Snippets Groups Projects
Commit 71ba71e2 authored by Xuefeng Ding's avatar Xuefeng Ding
Browse files

update files and add tests

parent 129f104a
No related branches found
No related tags found
No related merge requests found
......@@ -31,5 +31,8 @@
],
"clangd.path": "clangd-17",
"jupyter.debugJustMyCode": false,
"debugpy.debugJustMyCode": false
"debugpy.debugJustMyCode": false,
"pylint.args": ["--prefer-stubs=true"],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false
}
%% Cell type:code id: tags:
``` python
import myproj.simulation as ms
import numpy as np
print(ms.add(1, 2))
print(ms.complex(1, 2))
print(np.array([1, 2, 3]))
```
%% Cell type:code id: tags:
``` python
import pylint
pylint.run_pylint(["myproj/simulation"])
```
%% Cell type:code id: tags:
``` python
from astroid.interpreter._import import util
print(util.is_namespace("myproj"))
```
%% Cell type:code id: tags:
``` python
import json
from io import StringIO
import pylint.lint
from pylint.reporters import JSONReporter
# Adjust PYTHONPATH
# sys.path.append('/datafs/users/dingxf/neutrino-physics-tutorial/scikit-build-cpp-python')
# Define the Pylint options
pylint_options = [
"--reports=n",
"--output-format=json",
"--extension-pkg-allow-list=simulation._csrc._hello",
"--prefer-stubs=true",
"--clear-cache-post-run=y",
"/datafs/users/dingxf/neutrino-physics-tutorial/scikit-build-cpp-python/python/myproj/simulation/core.py", # The file you want to lint
]
# Create a StringIO buffer to capture Pylint output
pylint_output = StringIO()
reporter = JSONReporter(output=pylint_output)
# Run Pylint
pylint.lint.Run(pylint_options, reporter=reporter, exit=True)
# Get the output
output = pylint_output.getvalue()
# Parse and display the results
results = json.loads(output)
print(json.dumps(results, indent=2))
```
......
from ._csrc._hello import add, complexf
def div(a: float, b: float) -> float:
return a / b
def complex2(a: float, b: float) -> float:
return complexf(a, b) + add(a, b)
#############################################################################
# Author: Xuefeng Ding <dingxf@ihep.ac.cn> @ IHEP-CAS
#
# Project: cpp-python-small
# Date: 2024 November 17th
# Version: v1.0
# Description:
# Boilerplate for c++-python project.
# Can be installed with `pip install .`
#
# Maintainer:
# Xuefeng Ding <dingxf@ihep.ac.cn>
#
# All rights reserved. 2024 copyrighted.
#############################################################################
import pytest
from myproj.simulation import add, complexf
@pytest.mark.parametrize(
"a, b, expected",
[
(1, 2, 3),
(10, 15, 25),
(-5, 5, 0),
(0, 0, 0),
],
)
def test_add_parametrized(a: float, b: float, expected: float) -> None:
assert add(a, b) == expected
@pytest.mark.parametrize(
"a, b, expected",
[
(0, 1, 3),
(10, -5, 7),
(-10, -10, -18),
],
)
def test_myclass_parametrized(a: float, b: float, expected: float) -> None:
assert complexf(a, b) == expected
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment