Skip to content

Commit

Permalink
Fix #242 Meson tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krystophny committed Jan 5, 2025
1 parent c98ad34 commit 930a182
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 29 deletions.
2 changes: 1 addition & 1 deletion examples/fortran_oo/Makefile.meson
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ NAME := pywrapper
WRAPFLAGS += --type-check --kind-map kind.map

test: build
$(PYTHON) tests.py
$(PYTHON) oowrap_test.py
2 changes: 1 addition & 1 deletion examples/optional_string/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_string_in_array_2(self):
@unittest.skipIf(version.parse(np.version.version) < version.parse("1.24.0") , "This test is known to fail on numpy version older than 1.24.0")
def test_string_in_array_3(self):
in_array = np.array(['one ', 'four '], dtype='S6')
with self.assertRaises(RuntimeError) as context:
with self.assertRaises((RuntimeError, UnicodeDecodeError)) as context:
m_string_test.string_in_array(in_array)

def test_string_to_string(self):
Expand Down
1 change: 1 addition & 0 deletions examples/output_kind/Makefile.meson
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include ../make.meson.inc

NAME := pywrapper
WRAPFLAGS += --type-check --kind-map kind.map

test: build
$(PYTHON) test.py
6 changes: 3 additions & 3 deletions examples/remove_pointer_arg/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

class TestReturnArray(unittest.TestCase):

def not_ignored(self):
def test_not_ignored(self):
_ = m_test.not_to_be_ignored()

def ignored_1(self):
def test_ignored_1(self):
with self.assertRaises(AttributeError):
_ = m_test.to_be_ignored_1()

def ignored_2(self):
def test_ignored_2(self):
with self.assertRaises(AttributeError):
_ = m_test.to_be_ignored_2()

Expand Down
2 changes: 1 addition & 1 deletion examples/return_array/Makefile.meson
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ include ../make.meson.inc
NAME := pywrapper

test: build
$(PYTHON) tests.py
$(PYTHON) test.py
3 changes: 2 additions & 1 deletion examples/string_array_input_f2py/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ f2py: ${OBJ} ${SIGNATURES}
CFLAGS="${CFLAGS}" ${F2PY} -c -m _${PY_MOD}_no_sign ${F2PYFLAGS} ${F90_SRC}

test: f2py
${PYTHON} tests.py
${PYTHON} tests_sign.py
${PYTHON} tests_no_sign.py
7 changes: 5 additions & 2 deletions examples/string_array_input_f2py/Makefile.meson
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
include ../make.meson.inc

NAME := pywrapper
NAME := pywrapper_no_sign

test: build
$(PYTHON) tests.py
echo "TODO: Fix meson build for tests without signatures"
# $(PYTHON) tests_no_sign.py
echo "TODO: Add tests_sign.py once meson build support signatures"
# $(PYTHON) tests_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,8 @@
import numpy as np
from packaging import version

import _pywrapper_sign
import _pywrapper_no_sign

class TestWithSignature(unittest.TestCase):

@unittest.skipIf(version.parse(np.version.version) < version.parse("1.24.0") , "f2py bug solved https://github.com/numpy/numpy/issues/24706")
def test_string_in_array(self):
in_array = np.array(['one', 'two'], dtype='S3')
output = _pywrapper_sign.string_in_array(in_array)
self.assertEqual(output, 0)

@unittest.skipIf(version.parse(np.version.version) < version.parse("1.24.0") , "f2py bug solved https://github.com/numpy/numpy/issues/24706")
def test_string_in_array_optional_present(self):
in_array = np.array(['one', 'two'], dtype='S3')
output = _pywrapper_sign.string_in_array_optional(in_array)
self.assertEqual(output, 0)

def test_string_in_array_optional_not_present(self):
with self.assertRaises((SystemError, ValueError)):
_ = _pywrapper_sign.string_in_array_optional()

class TestWithoutSignature(unittest.TestCase):

@unittest.skipIf(version.parse(np.version.version) < version.parse("1.24.0") , "This test is known to fail on numpy version older than 1.24.0, dtype=S# does not work")
Expand Down
28 changes: 28 additions & 0 deletions examples/string_array_input_f2py/tests_sign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import unittest
import numpy as np
from packaging import version

import _pywrapper_sign

class TestWithSignature(unittest.TestCase):

@unittest.skipIf(version.parse(np.version.version) < version.parse("1.24.0") , "f2py bug solved https://github.com/numpy/numpy/issues/24706")
def test_string_in_array(self):
in_array = np.array(['one', 'two'], dtype='S3')
output = _pywrapper_sign.string_in_array(in_array)
self.assertEqual(output, 0)

@unittest.skipIf(version.parse(np.version.version) < version.parse("1.24.0") , "f2py bug solved https://github.com/numpy/numpy/issues/24706")
def test_string_in_array_optional_present(self):
in_array = np.array(['one', 'two'], dtype='S3')
output = _pywrapper_sign.string_in_array_optional(in_array)
self.assertEqual(output, 0)

def test_string_in_array_optional_not_present(self):
with self.assertRaises((SystemError, ValueError)):
_ = _pywrapper_sign.string_in_array_optional()


if __name__ == '__main__':

unittest.main()
2 changes: 1 addition & 1 deletion examples/type_check/Makefile.meson
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include ../make.meson.inc

NAME := pywrapper
WRAPFLAGS += --type-check
WRAPFLAGS += --type-check --kind-map kind.map

test: build
$(PYTHON) type_check_test.py

0 comments on commit 930a182

Please sign in to comment.