def test_code_29_output_52_2(capsys):
    def prints_too_much(condition):
        print("called with", condition)
        # if condition:             # phmdoctest:omit
        #     print("-" * 50)
        #     # note the section continues across blank lines
        #
        #     print("=" * 50)
        #     print("*" * 50)

        # Can't use phmdoctest:omit on the next line because
        # the else: line would get a Python SyntaxError.
        if condition:
            # So use phmdoctest:pass on the next line.
            pass  # print("condition is true")  # phmdoctest:pass
        else:
            print("condition is false")
        print("done")

    prints_too_much(True)
    prints_too_much(False)

    _phm_expected_str = """\
called with True
done
called with False
condition is false
done
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
Example #2
0
def test_code_47_output_51(capsys):
    print(mylist == [1, 2, 3, 4])

    _phm_expected_str = """\
True
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
def test_code_75_output_79(capsys):
    print(grades == ["A", "B", "C", "D"])

    _phm_expected_str = """\
True
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
Example #4
0
def test_code_286_output_311(capsys):
    class ExampleDescriptor:
        def __init(self):
            self._value = None

        def __get__(self, instance, type=None):
            print("I am a get method")
            return self._value

        def __set__(self, instance, value):
            print("I am a set method")
            self._value = value

    class ExampleObject:
        prop = ExampleDescriptor()

    test = ExampleObject()
    print("##")
    test.prop = 1
    print("##")
    print(test.prop)
    print("##")

    _phm_expected_str = """\
##
I am a set method
##
I am a get method
1
##
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
def test_mark_skip(capsys):
    print("testing @pytest.mark.skip().")

    _phm_expected_str = """\
incorrect expected output
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
Example #6
0
def test_code_9_output_14(capsys):
    squares = [1, 4, 9, 16, 25]
    print(squares)

    _phm_expected_str = """\
[1, 4, 9, 16, 25]
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
Example #7
0
def test_code_37_output_42(capsys):
    mylist.append(4)
    print(mylist)

    _phm_expected_str = """\
[1, 2, 3, 4]
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
def test_code_13_output_17(capsys):
    not_shared = "Hello World!"
    print(not_shared)

    _phm_expected_str = """\
Hello World!
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
def test_fstring(capsys):
    user = "******"
    print(f"{user=}")

    _phm_expected_str = """\
user='******'
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
Example #10
0
def test_code_85_output_93(capsys, managenamespace):
    hex_digits = string.hexdigits
    print(hex_digits)

    _phm_expected_str = """\
0123456789abcdefABCDEF
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
    managenamespace(operation="update", additions=locals())
Example #11
0
def test_code_87_output_94(capsys):
    from datetime import date

    d = date.fromordinal(730920)  # 730920th day after 1. 1. 0001
    print(d)

    _phm_expected_str = """\
2002-03-11
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
def test_code_353_output_359(capsys):
    l = Line(1, 2, 3, 4)
    p = Point('p')
    p.constrain_with(CoincidentConstraint(l))
    print(repr(p.x))

    _phm_expected_str = """\
ConstraintSet()
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
Example #13
0
def test_code_44_output_51(capsys):
    words = ["cat", "window", "defenestrate"]
    for w in words:
        print(w, len(w))

    _phm_expected_str = """\
cat 3
window 6
defenestrate 12
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
Example #14
0
def test_code_144_output_149(capsys, managenamespace):
    p = Point(1, 2)
    print(type(p.x).__name__)
    print(type(p.y).__name__)

    _phm_expected_str = """\
ConstrainedValue
ConstrainedValue
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
    managenamespace(operation="update", additions=locals())
Example #15
0
def test_code_185_output_191(capsys, managenamespace):
    p = Point(1, 2)
    print(f"p.x is {p.x.resolve()}")
    print(f"p.y is {p.y.resolve()}")

    _phm_expected_str = """\
p.x is 1
p.y is 2
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
    managenamespace(operation="update", additions=locals())
Example #16
0
def test_code_268_output_274(capsys, managenamespace):
    p = Point(1, 2)
    q = Point()
    q.x = p.x
    print(f"q.x is {q.x.resolve()}")

    _phm_expected_str = """\
q.x is 1
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
    managenamespace(operation="update", additions=locals())
Example #17
0
def test_code_108_output_114(capsys, managenamespace):
    print("Names are cleared after the code runs.")
    print(grades == ["A", "B", "C", "D"])
    print(hex_digits)

    _phm_expected_str = """\
Names are cleared after the code runs.
True
0123456789abcdefABCDEF
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
    managenamespace(operation="clear")
Example #18
0
def test_code_750_output_756(capsys, managenamespace):
    p = Point('p', 1, 2)
    print(p.x)
    c = LinkedValueConstraint(p.x)
    print(c)

    _phm_expected_str = """\
p.x
LinkedValueConstraint<p.x>
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
    managenamespace(operation="update", additions=locals())
Example #19
0
def test_code_23_output_32_1(capsys):

    print(mylist)
    raiser()
    # if mylist:                                 # phmdoctest:omit
    #     print("I should be commented out").
    #     assert False

    _phm_expected_str = """\
[1, 2, 3]
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
Example #20
0
def test_code_633_output_638(capsys, managenamespace):
    p = Point(1, 2)
    c = LinkedValueConstraint(p.x)
    print(c)

    _phm_expected_str = """\
LinkedValueConstraint<ConstraintSet(
    FixedValueConstraint<1>
)>
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
    managenamespace(operation="update", additions=locals())
Example #21
0
def test_code_53_output_60(capsys):
    print("string.digits=", string.digits)
    print(incrementer(10))
    print(grades)
    print(x, y, z)

    _phm_expected_str = """\
string.digits= 0123456789
11
['A', 'B', 'C']
77 88 99
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
Example #22
0
def test_code_20_output_27(capsys):
    print("math.pi=", round(math.pi, 3))
    print(mylist)
    print(a, b)
    print("doubler(16)=", doubler(16))

    _phm_expected_str = """\
math.pi= 3.142
[1, 2, 3]
10 11
doubler(16)= 32
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
def test_code_11_output_21_2(capsys):
    def cause_assertion():
        print("before assert...")
        # assert False                  # phmdoctest:omit
        print("after assert.")
        # print("bye")  # phmdoctest:omit

    cause_assertion()

    _phm_expected_str = """\
before assert...
after assert.
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
def test_code_825_output_833(capsys, managenamespace):
    p = Point()
    l = LinkedValueConstraint(p.x)
    m = LinkedValueConstraint(p.x)
    n = LinkedValueConstraint(q.x)
    print(f"l == m: {l == m}")
    print(f"l == n: {l == n}")

    _phm_expected_str = """\
l == m: True
l == n: False
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
    managenamespace(operation="update", additions=locals())
def test_code_698_output_706(capsys, managenamespace):
    p = Point('p')
    q = Point('q')

    q.x = p.x
    print(f"p.x is {repr(p.x)}")
    print(f"q.x is {repr(q.x)}")

    _phm_expected_str = """\
p.x is ConstraintSet()
q.x is ConstraintSet(
    LinkedValueConstraint<p.x>
)
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
    managenamespace(operation="update", additions=locals())
def test_code_599_output_606(capsys, managenamespace):
    l = Line(1, 2, 3, 4)
    p = Point('p')
    p.constrain_with(CoincidentConstraint(l))
    print(f"p is {repr(p)}")
    print(f"p.x is {repr(p.x)}")

    _phm_expected_str = """\
p is Point(
    CoincidentConstraint<Line<(1,2),(3,4)>>
)
p.x is ConstraintSet(
    InfluencedConstraint<CoincidentConstraint<Line<(1,2),(3,4)>>>
)
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
    managenamespace(operation="update", additions=locals())
def test_code_196_output_210(capsys, managenamespace):
    class Line:
        def __init__(self, x1, y1, x2, y2):
            self.x1 = x1
            self.y1 = y1
            self.x2 = x2
            self.y2 = y2

        def __repr__(self):
            return f"Line<({self.x1},{self.y1}),({self.x2},{self.y2})>"

    l = Line(0, 1, 2, 3)
    print(l)

    _phm_expected_str = """\
Line<(0,1),(2,3)>
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
    managenamespace(operation="update", additions=locals())
Example #28
0
def test_code_14_output_28(capsys):
    from enum import Enum

    class Floats(Enum):
        APPLES = 1
        CIDER = 2
        CHERRIES = 3
        ADUCK = 4

    for floater in Floats:
        print(floater)

    _phm_expected_str = """\
Floats.APPLES
Floats.CIDER
Floats.CHERRIES
Floats.ADUCK
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
Example #29
0
def test_code_855_output_866(capsys, managenamespace):
    p = Point('p', 1, 2)
    q = Point('q')
    print(f"p.x is {p.x}")
    print(f"p.x resolves to {p.x.resolve()}")
    q.x = p.x
    print(f"q.x is {repr(q.x)}")
    print(f"q.x resolves to {q.x.resolve()}")
    p.x = 2
    print(f"Now p.x has changed, q.x resolves to {q.x.resolve()}")

    _phm_expected_str = """\
p.x is p.x
p.x resolves to 1
q.x is ConstraintSet(
    LinkedValueConstraint<p.x>
)
q.x resolves to 1
Now p.x has changed, q.x resolves to 2
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
    managenamespace(operation="update", additions=locals())
def test_code_246_output_263(capsys, managenamespace):
    class CoincidentConstraint(Constraint):
        def __init__(self, line):
            self._line = line

        @property
        def line(self):
            return self._line

        def __repr__(self):
            return f"{self.__class__.__name__}<{self.line}>"

    l = Line(1, 2, 3, 4)
    p = Point('p')
    p.constrain_with(CoincidentConstraint(l))
    print(repr(p))

    _phm_expected_str = """\
ConstraintSet(
    CoincidentConstraint<Line<(1,2),(3,4)>>
)
"""
    _phm_compare_exact(a=_phm_expected_str, b=capsys.readouterr().out)
    managenamespace(operation="update", additions=locals())