2020-10-13 11:18:07 +00:00
|
|
|
# Copyright The PyTorch Lightning team.
|
|
|
|
#
|
|
|
|
# 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.
|
2020-07-27 23:07:09 +00:00
|
|
|
import pickle
|
|
|
|
|
|
|
|
import cloudpickle
|
|
|
|
import pytest
|
|
|
|
|
2021-03-20 18:58:59 +00:00
|
|
|
from tests import PATH_DATASETS
|
2021-02-08 10:52:02 +00:00
|
|
|
from tests.helpers.datasets import AverageDataset, MNIST, TrialMNIST
|
2020-07-27 23:07:09 +00:00
|
|
|
|
|
|
|
|
2021-03-23 20:43:21 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'dataset_cls,args', [
|
|
|
|
(MNIST, dict(root=PATH_DATASETS)),
|
|
|
|
(TrialMNIST, dict(root=PATH_DATASETS)),
|
|
|
|
(AverageDataset, dict()),
|
|
|
|
]
|
|
|
|
)
|
2021-03-20 18:58:59 +00:00
|
|
|
def test_pickling_dataset_mnist(tmpdir, dataset_cls, args):
|
|
|
|
mnist = dataset_cls(**args)
|
2020-07-27 23:07:09 +00:00
|
|
|
|
|
|
|
mnist_pickled = pickle.dumps(mnist)
|
2020-12-21 05:40:55 +00:00
|
|
|
pickle.loads(mnist_pickled)
|
2020-07-27 23:07:09 +00:00
|
|
|
# assert vars(mnist) == vars(mnist_loaded)
|
|
|
|
|
|
|
|
mnist_pickled = cloudpickle.dumps(mnist)
|
2020-12-21 05:40:55 +00:00
|
|
|
cloudpickle.loads(mnist_pickled)
|
2020-07-27 23:07:09 +00:00
|
|
|
# assert vars(mnist) == vars(mnist_loaded)
|