File: test_representation_mixin.py

package info (click to toggle)
python-parsl 2025.01.13%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,072 kB
  • sloc: python: 23,817; makefile: 349; sh: 276; ansic: 45
file content (68 lines) | stat: -rw-r--r-- 1,633 bytes parent folder | download
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import pytest

from parsl.utils import RepresentationMixin


class GoodRepr(RepresentationMixin):
    def __init__(self, x, y):
        self.x = x
        self.y = y


class BadRepr(RepresentationMixin):
    """This class incorrectly subclasses RepresentationMixin.
    It does not store the parameter x on self.
    """
    def __init__(self, x, y):
        self.y = y


@pytest.mark.local
def test_repr_good():
    p1 = "parameter 1"
    p2 = "the second parameter"

    # repr should not raise an exception
    r = repr(GoodRepr(p1, p2))

    # representation should contain both values supplied
    # at object creation.
    assert p1 in r
    assert p2 in r


@pytest.mark.local
def test_repr_bad():
    p1 = "parameter 1"
    p2 = "the second parameter"

    # repr should raise an exception
    with pytest.raises(AttributeError):
        repr(BadRepr(p1, p2))


class NonValidatingRepresentationMixin(RepresentationMixin):
    """This will override the process level RepresentationMixin which can
    be set to validating mode by pytest fixtures"""
    _validate_repr = False


class BadReprNonValidating(NonValidatingRepresentationMixin):
    """This class incorrectly subclasses RepresentationMixin.
    It does not store the parameter x on self.
    """
    def __init__(self, x, y):
        self.y = y


@pytest.mark.local
def test_repr_bad_unvalidated():
    p1 = "parameter 1"
    p2 = "the second parameter"

    # repr should not raise an exception
    r = repr(BadReprNonValidating(p1, p2))
    # parameter 2 should be found in the representation, but not
    # parameter 1
    assert p1 not in r
    assert p2 in r