Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-10-12 09:57:38 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-10-12 09:57:38 +0300
commit3d35d4a9e5ca39523d8ce13f8470e2b3ba59d958 (patch)
tree56c075332595653a7e356e79270c65da1d1d9f0d /tests
parent7b0b050dd5a837f52eb0801918427e2854fa64f0 (diff)
Tests: support running ID-property test without numpy
Diffstat (limited to 'tests')
-rw-r--r--tests/python/bl_pyapi_idprop.py75
1 files changed, 41 insertions, 34 deletions
diff --git a/tests/python/bl_pyapi_idprop.py b/tests/python/bl_pyapi_idprop.py
index bdf625c1c2e..4cee39fafb0 100644
--- a/tests/python/bl_pyapi_idprop.py
+++ b/tests/python/bl_pyapi_idprop.py
@@ -4,9 +4,13 @@
import bpy
import idprop
import unittest
-import numpy as np
from array import array
+# Run if `numpy` is installed.
+try:
+ import numpy as np
+except ImportError:
+ np = None
class TestHelper:
@@ -189,38 +193,6 @@ class TestIdPropertyGroupView(TestHelper, unittest.TestCase):
class TestBufferProtocol(TestHelper, unittest.TestCase):
- def test_int(self):
- self.id["a"] = array("i", [1, 2, 3, 4, 5])
- a = np.frombuffer(self.id["a"], self.id["a"].typecode)
- self.assertEqual(len(a), 5)
- a[2] = 10
- self.assertEqual(self.id["a"].to_list(), [1, 2, 10, 4, 5])
-
- def test_float(self):
- self.id["a"] = array("f", [1.0, 2.0, 3.0, 4.0])
- a = np.frombuffer(self.id["a"], self.id["a"].typecode)
- self.assertEqual(len(a), 4)
- a[-1] = 10
- self.assertEqual(self.id["a"].to_list(), [1.0, 2.0, 3.0, 10.0])
-
- def test_double(self):
- self.id["a"] = array("d", [1.0, 2.0, 3.0, 4.0])
- a = np.frombuffer(self.id["a"], self.id["a"].typecode)
- a[1] = 10
- self.assertEqual(self.id["a"].to_list(), [1.0, 10.0, 3.0, 4.0])
-
- def test_full_update(self):
- self.id["a"] = array("i", [1, 2, 3, 4, 5, 6])
- a = np.frombuffer(self.id["a"], self.id["a"].typecode)
- a[:] = [10, 20, 30, 40, 50, 60]
- self.assertEqual(self.id["a"].to_list(), [10, 20, 30, 40, 50, 60])
-
- def test_partial_update(self):
- self.id["a"] = array("i", [1, 2, 3, 4, 5, 6, 7, 8])
- a = np.frombuffer(self.id["a"], self.id["a"].typecode)
- a[1:5] = [10, 20, 30, 40]
- self.assertEqual(self.id["a"].to_list(), [1, 10, 20, 30, 40, 6, 7, 8])
-
def test_copy(self):
self.id["a"] = array("i", [1, 2, 3, 4, 5])
self.id["b"] = self.id["a"]
@@ -246,6 +218,42 @@ class TestBufferProtocol(TestHelper, unittest.TestCase):
self.assertEqual(list(view1), list(view2))
self.assertEqual(view1.tobytes(), view2.tobytes())
+
+if np is not None:
+ class TestBufferProtocol_Numpy(TestHelper, unittest.TestCase):
+ def test_int(self):
+ self.id["a"] = array("i", [1, 2, 3, 4, 5])
+ a = np.frombuffer(self.id["a"], self.id["a"].typecode)
+ self.assertEqual(len(a), 5)
+ a[2] = 10
+ self.assertEqual(self.id["a"].to_list(), [1, 2, 10, 4, 5])
+
+ def test_float(self):
+ self.id["a"] = array("f", [1.0, 2.0, 3.0, 4.0])
+ a = np.frombuffer(self.id["a"], self.id["a"].typecode)
+ self.assertEqual(len(a), 4)
+ a[-1] = 10
+ self.assertEqual(self.id["a"].to_list(), [1.0, 2.0, 3.0, 10.0])
+
+ def test_double(self):
+ self.id["a"] = array("d", [1.0, 2.0, 3.0, 4.0])
+ a = np.frombuffer(self.id["a"], self.id["a"].typecode)
+ a[1] = 10
+ self.assertEqual(self.id["a"].to_list(), [1.0, 10.0, 3.0, 4.0])
+
+ def test_full_update(self):
+ self.id["a"] = array("i", [1, 2, 3, 4, 5, 6])
+ a = np.frombuffer(self.id["a"], self.id["a"].typecode)
+ a[:] = [10, 20, 30, 40, 50, 60]
+ self.assertEqual(self.id["a"].to_list(), [10, 20, 30, 40, 50, 60])
+
+ def test_partial_update(self):
+ self.id["a"] = array("i", [1, 2, 3, 4, 5, 6, 7, 8])
+ a = np.frombuffer(self.id["a"], self.id["a"].typecode)
+ a[1:5] = [10, 20, 30, 40]
+ self.assertEqual(self.id["a"].to_list(), [1, 10, 20, 30, 40, 6, 7, 8])
+
+
class TestRNAData(TestHelper, unittest.TestCase):
def test_custom_properties_none(self):
@@ -309,7 +317,6 @@ class TestRNAData(TestHelper, unittest.TestCase):
self.assertEqual(rna_data["default"], [1, 2])
-
if __name__ == '__main__':
import sys
sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [])