Skip to content

Commit 906ee79

Browse files
authored
Merge pull request #26 from BAMresearch/fix_formatting_for_tox
Fix formatting for tox
2 parents cbd7f87 + afd0492 commit 906ee79

File tree

10 files changed

+45
-124
lines changed

10 files changed

+45
-124
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@
8585
+ r".*",
8686
# attempted fix of '406 Client Error: Not Acceptable for url'
8787
# https://github.com/sphinx-doc/sphinx/issues/1331
88-
join(project_meta["project"]["urls"]["repository"], "commit", r"[0-9a-fA-F]+")
88+
join(project_meta["project"]["urls"]["repository"], "commit", r"[0-9a-fA-F]+"),
8989
]

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
attrs
2-
dask
32
entrypoints
43
matplotlib
54
numpy
@@ -8,6 +7,6 @@ h5py
87
pint
98
pytest
109
stamina
11-
tiled
1210
tox
1311
scipy
12+
uncertainties

src/modacor/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# -*- coding: utf-8 -*-
22
# __init__.py
33

4-
__version__ = '0.0.0'
4+
__version__ = "0.0.0"
55

66
from pint import UnitRegistry, set_application_registry
7-
ureg = UnitRegistry(system='SI')
7+
8+
ureg = UnitRegistry(system="SI")
89
Q_ = ureg.Quantity
9-
# recommended for pickling and unpickling:
10+
# recommended for pickling and unpickling:
1011
set_application_registry(ureg)
1112
ureg.formatter.default_format = "~P"
1213
ureg.setup_matplotlib(True)

src/modacor/dataclasses/messagehandler.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# # -*- coding: utf-8 -*-
33

44
import logging
5+
56
logger = logging.getLogger(__name__)
67

78

@@ -13,7 +14,8 @@ class MessageHandler:
1314
Args:
1415
level (int): The logging level to use. Defaults to logging.INFO.
1516
"""
16-
def __init__(self, level: int = logging.INFO, name: str = 'MoDaCor', **kwargs):
17+
18+
def __init__(self, level: int = logging.INFO, name: str = "MoDaCor", **kwargs):
1719
self.level = level
1820
self.name = name
1921

@@ -23,7 +25,7 @@ def __init__(self, level: int = logging.INFO, name: str = 'MoDaCor', **kwargs):
2325
self.consoleLogHandler = logging.StreamHandler()
2426
self.consoleLogHandler.setLevel(level)
2527

26-
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
28+
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
2729
self.consoleLogHandler.setFormatter(formatter)
2830
self.logger.addHandler(self.consoleLogHandler)
2931

@@ -33,20 +35,20 @@ def log(self, message: str, level: int = None, name: str = None):
3335

3436
if name is None:
3537
name = self.name
36-
38+
3739
self.logger(message, level=level, name=name)
3840

3941
def info(self, message: str):
40-
self.log(message, level=logging.INFO, name='MoDaCor')
42+
self.log(message, level=logging.INFO, name="MoDaCor")
4143

4244
def warning(self, message: str):
43-
self.log(message, level=logging.WARNING, name='MoDaCor')
45+
self.log(message, level=logging.WARNING, name="MoDaCor")
4446

4547
def error(self, message: str):
46-
self.log(message, level=logging.ERROR, name='MoDaCor')
48+
self.log(message, level=logging.ERROR, name="MoDaCor")
4749

4850
def critical(self, message: str):
49-
self.log(message, level=logging.CRITICAL, name='MoDaCor')
50-
51+
self.log(message, level=logging.CRITICAL, name="MoDaCor")
52+
5153
def debug(self, message: str):
52-
self.log(message, level=logging.DEBUG, name='MoDaCor')
54+
self.log(message, level=logging.DEBUG, name="MoDaCor")

src/modacor/dataclasses/process_step.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
__all__ = ["ProcessStep"]
55
__license__ = "BSD-3-Clause"
6+
__version__ = "0.0.1"
67

78

89
from abc import abstractmethod
910
from numbers import Integral
11+
from pathlib import Path
1012
from typing import Any
1113

1214
from attrs import define, field
@@ -26,7 +28,12 @@ class ProcessStep:
2628
io_sources: IoSources = field()
2729

2830
# class attribute for a machine-readable description of the process step
29-
documentation: ProcessStepDescriber
31+
documentation = ProcessStepDescriber(
32+
calling_name="Generic Process step",
33+
calling_id=None,
34+
calling_module_path=Path(__file__),
35+
calling_version=__version__,
36+
)
3037

3138
# dynamic instance configuration
3239
configuration: dict = field(factory=dict, validator=v.instance_of(dict))
@@ -45,9 +52,8 @@ class ProcessStep:
4552
default=MessageHandler(), validator=v.instance_of(MessageHandler)
4653
)
4754

48-
# a list of data keys that are modified by this process
49-
def __attrs_post_init__(self):
50-
self.__prepared = False
55+
# internal variables:
56+
__prepared: bool = field(default=False, validator=v.instance_of(bool))
5157

5258
def prepare_execution(self):
5359
"""
@@ -94,5 +100,5 @@ def modify_config(self, key: str, value: Any):
94100
if key in self.configuration:
95101
self.configuration[key] = value
96102
else:
97-
raise KeyError(f"Key {key} not found in configuration")
103+
raise KeyError(f"Key {key} not found in configuration") # noqa
98104
self.__prepared = False

src/modacor/dataclasses/validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from numbers import Integral
6-
from typing import Any
6+
from typing import Any, Type
77

88
import pint
99

@@ -19,7 +19,7 @@
1919
]
2020

2121

22-
def is_list_of_ints(value: Any):
22+
def is_list_of_ints(instance: Type, attribute: str, value: Any):
2323
"""
2424
Check if the value is a list of integers.
2525
"""

src/modacor/io/hdf/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,3 @@
2525
__license__ = "BSD-3-Clause"
2626
__copyright__ = "Copyright 2025 MoDaCor Authors"
2727
__status__ = "Alpha"
28-
29-
30-
from ..io_source import IoSource
31-
from ..io_sources import IoSources

src/modacor/math/variance_calculations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ def divide(x, vx, y, vy=0):
7070
∂/∂y = -x / y^2
7171
"""
7272
result = x / y
73-
dx_, dy_ = 1 / y, -x / (y ** 2)
73+
dx_, dy_ = 1 / y, -x / (y**2)
7474
variance = dx_**2 * vx + dy_**2 * vy
7575
return result, variance
Lines changed: 5 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,12 @@
1-
from datetime import datetime, timedelta, timezone
2-
from pathlib import Path
1+
from modacor.dataclasses.process_step import ProcessStep
2+
from modacor.io import IoSources
33

4-
import pytest
5-
6-
from ..dataclasses.process_step import ProcessStep
7-
8-
9-
# Dummy BaseData for testing execute() since ProcessStep.execute() requires it.
10-
class DummyBaseData:
11-
pass
4+
TEST_IO_SOURCES = IoSources()
125

136

147
def test_minimal_instantiation():
158
"""
169
Test that a ProcessStep can be instantiated with only the minimal arguments.
1710
"""
18-
ps = ProcessStep(
19-
calling_name="Test Process",
20-
calling_id="proc_001",
21-
calling_module_path=Path("src/modacor/modules/some_module.py"),
22-
calling_version="1.0",
23-
)
24-
assert ps is not None
25-
26-
27-
def test_full_instantiation():
28-
"""
29-
Test that a ProcessStep can be instantiated with all arguments.
30-
"""
31-
ps = ProcessStep(
32-
calling_name="Test Process",
33-
calling_id="proc_002",
34-
calling_module_path=Path("src/modacor/modules/some_module.py"),
35-
calling_version="1.0",
36-
required_data_keys=["fish", "cake"],
37-
calling_arguments={"fish": "salmon", "cake": "chocolate"},
38-
step_keywords=["test", "full"],
39-
step_doc="Test full instantiation",
40-
step_reference="doi: 10.1234/5678",
41-
step_note="I am a note.",
42-
# produced_values={}, # this is internally generated
43-
use_frames_cache=["fish"],
44-
use_overall_cache=["cake"],
45-
saved={"cake": "/path/to/cake"},
46-
)
47-
ps.start()
48-
ps.stop()
49-
assert ps is not None
50-
51-
52-
def test_missing_required_input():
53-
"""
54-
Test that a ProcessStep can be instantiated with all arguments.
55-
"""
56-
with pytest.raises(
57-
ValueError, match=r"Missing required data keys in calling_arguments: ['bread']"
58-
):
59-
ProcessStep(
60-
calling_name="Test Process",
61-
calling_id="proc_002",
62-
calling_module_path=Path("src/modacor/modules/some_module.py"),
63-
calling_version="1.0",
64-
required_data_keys=["fish", "cake", "bread"],
65-
calling_arguments={"fish": "salmon", "cake": "chocolate"},
66-
step_keywords=["test", "full"],
67-
step_doc="Test full instantiation",
68-
step_reference="doi: 10.1234/5678",
69-
step_note="I am a note.",
70-
# produced_values={}, # this is internally generated
71-
use_frames_cache=["fish"],
72-
use_overall_cache=["cake"],
73-
saved={"cake": "/path/to/cake"},
74-
)
75-
76-
77-
def test_duration_calculation():
78-
"""
79-
Test that the duration property correctly computes elapsed time.
80-
"""
81-
ps = ProcessStep(
82-
calling_name="Test Process",
83-
calling_id="proc_003",
84-
calling_module_path=Path("src/modacor/modules/some_module.py"),
85-
calling_version="1.0",
86-
required_data_keys=[],
87-
calling_arguments={},
88-
step_keywords=["test", "duration"],
89-
step_doc="Test duration calculation",
90-
step_reference="",
91-
step_note=None,
92-
produced_values={},
93-
use_frames_cache=[],
94-
)
95-
# Manually set start_time 5 seconds before now.
96-
ps.start_time = datetime.now(timezone.utc) - timedelta(seconds=5)
97-
ps.stop() # Sets stop_time to now.
98-
duration = ps.duration
99-
assert duration is not None and duration >= 5
11+
ps = ProcessStep(TEST_IO_SOURCES)
12+
assert isinstance(ps, ProcessStep)

src/modacor/tests/test_variance_calculations.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
`uncertainties` package. Randomly generated arrays simulate real-world numeric data
77
with associated variances.
88
"""
9+
910
import numpy as np
11+
from uncertainties.unumpy import nominal_values, std_devs, uarray
12+
1013
import modacor.math.variance_calculations as varc
11-
from uncertainties.unumpy import uarray, nominal_values, std_devs
1214

1315
samples = 1000
1416

17+
1518
def generate_samples(size, low=1, high=1.0e9):
1619
return np.random.uniform(low, high, size)
1720

21+
1822
def generate_error(values, add_zero_errors=False):
1923
s = np.sqrt(values)
2024
if add_zero_errors: # to check if scalars will work
@@ -35,7 +39,7 @@ def test_add():
3539
result, variances = varc.add(x, dx**2, y, dy**2)
3640

3741
assert np.allclose(result, nominal_values(expected))
38-
assert np.allclose(variances, std_devs(expected)**2)
42+
assert np.allclose(variances, std_devs(expected) ** 2)
3943

4044

4145
def test_subtract():
@@ -51,7 +55,7 @@ def test_subtract():
5155
result, variances = varc.subtract(x, dx**2, y, dy**2)
5256

5357
assert np.allclose(result, nominal_values(expected))
54-
assert np.allclose(variances, std_devs(expected)**2)
58+
assert np.allclose(variances, std_devs(expected) ** 2)
5559

5660

5761
def test_multiply():
@@ -67,7 +71,7 @@ def test_multiply():
6771
result, variances = varc.multiply(x, dx**2, y, dy**2)
6872

6973
assert np.allclose(result, nominal_values(expected))
70-
assert np.allclose(variances, std_devs(expected)**2)
74+
assert np.allclose(variances, std_devs(expected) ** 2)
7175

7276

7377
def test_divide():
@@ -83,4 +87,4 @@ def test_divide():
8387
result, variances = varc.divide(x, dx**2, y, dy**2)
8488

8589
assert np.allclose(result, nominal_values(expected))
86-
assert np.allclose(variances, std_devs(expected)**2)
90+
assert np.allclose(variances, std_devs(expected) ** 2)

0 commit comments

Comments
 (0)