Skip to content

Commit 61154bc

Browse files
authored
add bounds check for debug builds, run all unit tests on CI with DEBUG=1 (#194)
1 parent 657906d commit 61154bc

File tree

9 files changed

+31
-51
lines changed

9 files changed

+31
-51
lines changed

.github/workflows/tests+pypi.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
submodules: recursive
2424
fetch-depth: 0 # https://github.com/pypa/setuptools_scm/issues/480
2525
- run: DEBUG=1 VERBOSE=1 pip install --verbose -e .[tests]
26+
- run: pytest -v -s -We -p no:unraisableexception tests
2627

2728
build:
2829
needs: [debug_build_ok]
@@ -106,7 +107,7 @@ jobs:
106107
- run: |
107108
cd tests
108109
python -c "import PyPartMC"
109-
pytest --durations=10 -v -s -We -p no:unraisableexception -k 'not test_todos_annotated' .
110+
pytest --durations=10 -v -s -We -p no:unraisableexception .
110111
cd ..
111112
112113
- if: matrix.python-version != '3.7'

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
2323
add_compile_options($<$<COMPILE_LANGUAGE:Fortran>:-ffree-line-length-none>)
2424
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58175
2525
add_compile_options($<$<COMPILE_LANGUAGE:Fortran>:-Wno-surprising>)
26+
27+
add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:DEBUG>>:-fcheck=bounds>)
2628
endif()
2729

2830
macro(add_prefix prefix rootlist)

src/aero_state.F90

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,6 @@ subroutine f_aero_state_bin_average_comp(ptr_c, bin_grid_ptr_c, &
219219

220220
end subroutine
221221

222-
subroutine f_aero_state_copy(ptr_c,ptr_new_c) bind(C)
223-
type(c_ptr) :: ptr_c, ptr_new_c
224-
type(aero_state_t), pointer :: ptr_f => null()
225-
type(aero_state_t), pointer :: ptr_new_f => null()
226-
227-
call c_f_pointer(ptr_c,ptr_f)
228-
call c_f_pointer(ptr_new_c, ptr_new_f)
229-
230-
ptr_new_f = ptr_f
231-
end subroutine
232-
233222
subroutine f_aero_state_particle(ptr_c, ptr_particle_c, index) bind(C)
234223
type(c_ptr) :: ptr_c, ptr_particle_c
235224
integer(c_int) :: index

src/aero_state.hpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ extern "C" void f_aero_state_bin_average_comp(
101101
const void *aero_data_ptr
102102
) noexcept;
103103

104-
extern "C" void f_aero_state_copy(
105-
const void *ptr_c,
106-
const void *aero_dataptr
107-
) noexcept;
108-
109104
extern "C" void f_aero_state_particle(
110105
const void *ptr_c,
111106
const void *ptr_particle_c,
@@ -327,19 +322,6 @@ struct AeroState {
327322
);
328323
}
329324

330-
static AeroState* __deepcopy__(
331-
AeroState &self,
332-
py::dict &memo
333-
) {
334-
double n_part = 1.0;
335-
AeroState *ptr = new AeroState(n_part, self.aero_data);
336-
f_aero_state_copy(
337-
self.ptr.f_arg(),
338-
ptr
339-
);
340-
return ptr;
341-
}
342-
343325
static AeroParticle* get_particle(
344326
const AeroState &self,
345327
const int &idx

src/fake_spec_file.F90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ subroutine spec_file_read_real_named_array(file, max_lines, names, vals)
131131

132132
allocate(names(n_rows))
133133
allocate(vals(n_rows, n_cols))
134-
allocate(vals_row(n_cols))
134+
allocate(vals_row(max(1, n_cols)))
135135
do row = 1, n_rows
136136
name_size = len(names(row))
137137
call c_spec_file_read_real_named_array_data( &
@@ -246,15 +246,15 @@ subroutine spec_file_read_timed_real_array(file, name, times, vals)
246246
)
247247
allocate(times(times_size))
248248
allocate(vals(vals_size))
249+
if (size(times) < 1) then
250+
print*, 'must have at least one data poin in file ' // trim(file%name) // '::' // name
251+
call pmc_stop(925956383)
252+
end if
249253
call c_spec_file_read_timed_real_array_data(&
250254
name, len(name), &
251255
times(1), size(times), &
252256
vals(1), size(vals) &
253257
)
254-
if (size(times) < 1) then
255-
print*, 'must have at least one data poin in file ' // trim(file%name) // '::' // name
256-
call pmc_stop(925956383)
257-
end if
258258
end subroutine
259259

260260
subroutine spec_file_open(filename, file)

src/gas_data.F90

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,17 @@ subroutine f_gas_data_spec_by_name(ptr_c, value, name_data, name_size) &
5050
bind(C)
5151
type(gas_data_t), pointer :: ptr_f => null()
5252
type(c_ptr), intent(in) :: ptr_c
53-
character(kind=c_char), intent(in) :: name_data
53+
character(kind=c_char), dimension(*), intent(in) :: name_data
5454
integer(c_int), intent(in) :: name_size
55-
integer(c_int) :: value
55+
integer(c_int), intent(out) :: value
5656

57+
integer :: i
5758
character(len=name_size) :: name
5859

5960
call c_f_pointer(ptr_c, ptr_f)
60-
name = name_data(1:name_size)
61+
do i = 1, name_size
62+
name(i:i) = name_data(i)
63+
end do
6164
value = gas_data_spec_by_name(ptr_f, name)
6265

6366
end subroutine

src/pypartmc.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ PYBIND11_MODULE(_PyPartMC, m) {
160160
)
161161
.def(py::init<const double, std::shared_ptr<AeroData>>())
162162
.def("__len__", AeroState::__len__)
163-
.def("__deepcopy__", AeroState::__deepcopy__)
164163
.def_property_readonly("total_num_conc", AeroState::total_num_conc,
165164
"returns the total number concentration of the population")
166165
.def_property_readonly("total_mass_conc", AeroState::total_mass_conc,

tests/test_aero_state.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
####################################################################################################
66

77
import gc
8-
from copy import deepcopy
98

109
import numpy as np
1110
import pytest
@@ -69,17 +68,6 @@ def test_len(n_part):
6968
assert int(size) > n_part * 0.5
7069
assert int(size) < n_part * 2
7170

72-
@staticmethod
73-
def test_copy(sut_minimal): # pylint: disable=redefined-outer-name
74-
# act
75-
aero_state_copy = deepcopy(sut_minimal)
76-
77-
# assert
78-
assert aero_state_copy is not sut_minimal
79-
expected = np.sum(sut_minimal.diameters)
80-
actual = np.sum(aero_state_copy.diameters)
81-
assert expected == actual
82-
8371
@staticmethod
8472
def test_total_num_conc(sut_minimal): # pylint: disable=redefined-outer-name
8573
# act

tests/test_gas_data.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import json
88

9+
import pytest
10+
911
import PyPartMC as ppmc
1012

1113
GAS_DATA_CTOR_ARG_MINIMAL = ("SO2",)
@@ -46,3 +48,17 @@ def test_str():
4648

4749
# assert
4850
assert string == json.dumps(data, separators=(",", ":"))
51+
52+
@staticmethod
53+
@pytest.mark.parametrize(
54+
"ctor_arg", (GAS_DATA_CTOR_ARG_MINIMAL, ("SO2", "NO2"), ("A", "B", "C"))
55+
)
56+
def test_spec_by_name(ctor_arg):
57+
# arrange
58+
sut = ppmc.GasData(ctor_arg)
59+
60+
# act
61+
indices = [sut.spec_by_name(name) for name in ctor_arg]
62+
63+
# assert
64+
assert indices == list(range(len(ctor_arg)))

0 commit comments

Comments
 (0)