Commit a5696ae9 authored by Levin Zimmermann's avatar Levin Zimmermann

erp5_core_test: restricted: Test pandas resampler

In some projects we use pandas resampler inside 'portal_callables'
(so with restricted Python). But we miss tests which check
whether pandas resamplers are allowed inside the restricted Python.
Due to this lack of tests we won't notice whether the usage of pandas
resamplers still work with a newer pandas version. With this patch
we can recognize if an internal change of pandas makes the resampler unusuable
in restricted Python.

/reviewed-on nexedi/erp5!1738
/reviewed-by @jerome @klaus
parent 14b79ec0
...@@ -572,6 +572,39 @@ class TestRestrictedPythonSecurity(ERP5TypeTestCase): ...@@ -572,6 +572,39 @@ class TestRestrictedPythonSecurity(ERP5TypeTestCase):
expected=999 expected=999
) )
def testPandasDatetimeIndexResampler(self):
self.createAndRunScript('''
import pandas as pd
index = pd.date_range('1/1/2000', periods=9, freq='T')
series = pd.Series(range(9), index=index)
resampler = series.resample('3T')
return resampler.mean()[0]
''',
expected=1
)
def testPandasPeriodIndexResampler(self):
self.createAndRunScript('''
import pandas as pd
index = pd.period_range(start='2017-01-01', end='2018-01-01', freq='M')
series = pd.Series(range(len(index)), index=index)
resampler = series.resample('3T')
return resampler.mean()[0]
''',
expected=0.0
)
def testPandasTimedeltaIndexResampler(self):
self.createAndRunScript('''
import pandas as pd
index = pd.timedelta_range(start='1 day', periods=4)
series = pd.Series(range(len(index)), index=index)
resampler = series.resample('3T')
return resampler.mean()[0]
''',
expected=0.0
)
def testPandasIORead(self): def testPandasIORead(self):
# Test the black_list configuration validity # Test the black_list configuration validity
for read_method in pandas_black_list: for read_method in pandas_black_list:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment