GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — pythonnet/tests/test_repr.py at master · pythonnet/pythonnet Expand file tree/ Copy pathtest_repr.pyMore file actions 68 lines (55 loc) · 2.17 KB / Copy pathtest_repr.pyFile metadata and controls68 lines (55 loc) · 2.17 KB 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 # -*- coding: utf-8 -*- """Test __repr__ output""" import System import pytest from Python.Test import ReprTest def test_basic(): """Test Point class which implements both ToString and __repr__ without inheritance""" ob = ReprTest.Point(1,2) # point implements ToString() and __repr__() assert ob.__repr__() == "Point(1,2)" assert str(ob) == "Python.Test.ReprTest+Point: X=1, Y=2" def test_system_string(): """Test system string""" ob = System.String("hello") assert str(ob) == "hello" assert "<System.String object at " in ob.__repr__() def test_str_only(): """Test class implementing ToString() but not __repr__()""" ob = ReprTest.Bar() assert str(ob) == "I implement ToString() but not __repr__()!" assert "<Python.Test.Bar object at " in ob.__repr__() def test_hierarchy1(): """Test inheritance hierarchy with base & middle class implementing ToString""" ob1 = ReprTest.BazBase() assert str(ob1) == "Base class implementing ToString()!" assert "<Python.Test.BazBase object at " in ob1.__repr__() ob2 = ReprTest.BazMiddle() assert str(ob2) == "Middle class implementing ToString()!" assert "<Python.Test.BazMiddle object at " in ob2.__repr__() ob3 = ReprTest.Baz() assert str(ob3) == "Middle class implementing ToString()!" assert "<Python.Test.Baz object at " in ob3.__repr__() def bad_tostring(): """Test ToString that can't be used by str()""" ob = ReprTest.Quux() assert str(ob) == "Python.Test.ReprTest+Quux" assert "<Python.Test.Quux object at " in ob.__repr__() def bad_repr(): """Test incorrect implementation of repr""" ob1 = ReprTest.QuuzBase() assert str(ob1) == "Python.Test.ReprTest+QuuzBase" assert "<Python.Test.QuuzBase object at " in ob.__repr__() ob2 = ReprTest.Quuz() assert str(ob2) == "Python.Test.ReprTest+Quuz" assert "<Python.Test.Quuz object at " in ob.__repr__() ob3 = ReprTest.Corge() with pytest.raises(Exception): str(ob3) with pytest.raises(Exception): ob3.__repr__() ob4 = ReprTest.Grault() with pytest.raises(Exception): str(ob4) with pytest.raises(Exception): ob4.__repr__() |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |