From 5fb7eb212a7332bf1fde2ecfbc575c0316f42cac Mon Sep 17 00:00:00 2001
From: Iliya Manolov <ilmanfordinner@gmail.com>
Date: Mon, 12 Jun 2017 11:56:30 +0300
Subject: [PATCH] Float64 Numpy array test

@Tyagov

Added a test to check int64 and float64 Numpy arrays because an error like this existed before:

```
in Base_executeJupyter
     return json.dumps(result)
   Module json, line 244, in dumps
     return _default_encoder.encode(obj)
   Module json.encoder, line 207, in encode
     chunks = self.iterencode(o, _one_shot=True)
   Module json.encoder, line 270, in iterencode
     return _iterencode(o, 0)
   Module json.encoder, line 184, in default
     raise TypeError(repr(o) + " is not JSON serializable")
TypeError: array([[ -245554.,    19410.,  1453313.],
        [ -238947.,    18888.,  1443651.],
        [ -238416.,    18350.,  1444382.],
        ...,
        [ -250816.,    19482.,  1445528.],
        [ -251464.,    18678.,  1444711.],
        [ -253475.,    18786.,  1444842.]]) is not JSON serializable
```

/reviewed-on https://lab.nexedi.com/nexedi/erp5/merge_requests/285
---
 .../test.erp5.testExecuteJupyter.py           | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/bt5/erp5_data_notebook/TestTemplateItem/portal_components/test.erp5.testExecuteJupyter.py b/bt5/erp5_data_notebook/TestTemplateItem/portal_components/test.erp5.testExecuteJupyter.py
index 89ea08915d..ca0e1accc7 100644
--- a/bt5/erp5_data_notebook/TestTemplateItem/portal_components/test.erp5.testExecuteJupyter.py
+++ b/bt5/erp5_data_notebook/TestTemplateItem/portal_components/test.erp5.testExecuteJupyter.py
@@ -881,3 +881,46 @@ print dig
     self.tic()
 
     self.assertEquals(result, True)
+
+def testNPArrayPrint(self):
+  self.login('dev_user')
+  import_code = '''
+import numpy as np
+'''
+  reference = 'Test.Notebook.EnvironmentObject.Errors.NPArrayTest'
+  result = self.portal.Base_executeJupyter(
+    reference=reference,
+    python_expression=import_code
+  )
+  self.tic()
+
+  result = json.loads(result)
+  self.assertEquals(result['status'], 'ok')
+  
+  jupyter_code = '''
+print np.random.rand(256, 256, 256)
+'''
+
+  result = self.portal.Base_executeJupyter(
+    reference=reference,
+    python_expression=jupyter_code
+  )
+  self.tic()
+
+  result = json.loads(result)
+  self.assertEquals(result['status'], 'ok')
+
+  jupyter_code = '''
+print np.random.randint(low = 2 ** 63 - 1, size = (256, 256, 256), dtype = 'int64')
+'''
+
+  result = self.portal.Base_executeJupyter(
+    reference=reference,
+    python_expression=jupyter_code
+  )
+  self.tic()
+
+  result = json.loads(result)
+  self.assertEquals(result['status'], 'ok')
+
+  
\ No newline at end of file
-- 
2.30.9