File: test_pickle.py

package info (click to toggle)
python-affine 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 156 kB
  • ctags: 125
  • sloc: python: 690; makefile: 6
file content (30 lines) | stat: -rw-r--r-- 744 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
Validate that instances of `affine.Affine()` can be pickled and unpickled.
"""


import pickle
from multiprocessing import Pool

import affine


def test_pickle():
    a = affine.Affine(1, 2, 3, 4, 5, 6)
    assert pickle.loads(pickle.dumps(a)) == a


def _mp_proc(x):
    # A helper function - needed for test_with_multiprocessing()
    # Can't be defined inside the test because multiprocessing needs
    # everything to be in __main__
    assert isinstance(x, affine.Affine)
    return x


def test_with_multiprocessing():
    a1 = affine.Affine(1, 2, 3, 4, 5, 6)
    a2 = affine.Affine(6, 5, 4, 3, 2, 1)
    results = Pool(2).map(_mp_proc, [a1, a2])
    for expected, actual in zip([a1, a2], results):
        assert expected == actual