mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-28 09:59:22 +08:00
7892a6943f
on the number of per-tick update that occur since they were duplicated per each PerformancePeriod. Also opens up the path to cythonizing the entire object
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
#
|
|
# Copyright 2015 Quantopian, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import pickle
|
|
|
|
from nose_parameterized import parameterized
|
|
from unittest import TestCase
|
|
|
|
from .serialization_cases import (
|
|
object_serialization_cases,
|
|
assert_dict_equal
|
|
)
|
|
|
|
|
|
class PickleSerializationTestCase(TestCase):
|
|
|
|
@parameterized.expand(object_serialization_cases())
|
|
def test_object_serialization(self,
|
|
_,
|
|
cls,
|
|
initargs,
|
|
di_vars,
|
|
comparison_method='dict'):
|
|
|
|
obj = cls(*initargs)
|
|
for k, v in di_vars.items():
|
|
setattr(obj, k, v)
|
|
state = pickle.dumps(obj)
|
|
|
|
obj2 = pickle.loads(state)
|
|
for k, v in di_vars.items():
|
|
setattr(obj2, k, v)
|
|
|
|
if comparison_method == 'repr':
|
|
self.assertEqual(obj.__repr__(), obj2.__repr__())
|
|
elif comparison_method == 'to_dict':
|
|
assert_dict_equal(obj.to_dict(), obj2.to_dict())
|
|
else:
|
|
assert_dict_equal(obj.__dict__, obj2.__dict__)
|