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_constructors.py at v3.0.4 · pythonnet/pythonnet Expand file tree/ Copy pathtest_constructors.pyMore file actions 102 lines (66 loc) · 2.2 KB / Copy pathtest_constructors.pyFile metadata and controls102 lines (66 loc) · 2.2 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 # -*- coding: utf-8 -*- """Test CLR class constructor support.""" import pytest import sys import System def test_enum_constructor(): """Test enum constructor args""" from System import TypeCode from Python.Test import EnumConstructorTest ob = EnumConstructorTest(TypeCode.Int32) assert ob.value == TypeCode.Int32 def test_flags_constructor(): """Test flags constructor args""" from Python.Test import FlagsConstructorTest from System.IO import FileAccess flags = FileAccess.Read | FileAccess.Write ob = FlagsConstructorTest(flags) assert ob.value == flags def test_struct_constructor(): """Test struct constructor args""" from System import Guid from Python.Test import StructConstructorTest guid = Guid.NewGuid() ob = StructConstructorTest(guid) assert ob.value == guid def test_datetime(): inst = System.DateTime(2021, 12, 29) assert inst.Year == 2021 def test_subclass_constructor(): """Test subclass constructor args""" from Python.Test import SubclassConstructorTest class Sub(System.Exception): pass instance = Sub() ob = SubclassConstructorTest(instance) assert isinstance(ob.value, System.Exception) def test_multiple_constructor(): from Python.Test import MultipleConstructorsTest # Test parameterless ob = MultipleConstructorsTest() assert ob.value == "" def test_default_constructor_fallback(): from Python.Test import DefaultConstructorMatching ob = DefaultConstructorMatching(2) assert ob.a == 2 with pytest.raises(TypeError): ob = DefaultConstructorMatching("2") def test_constructor_leak(): from System import Uri from Python.Runtime import Runtime uri = Uri("http://www.python.org") Runtime.TryCollectingGarbage(20) ref_count = sys.getrefcount(uri) # check disabled due to GC uncertainty # assert ref_count == 1 def test_string_constructor(): from System import String, Char, Array ob = String('A', 10) assert ob == 'A' * 10 arr = Array[Char](10) for i in range(10): arr[i] = Char(str(i)) ob = String(arr) assert ob == "0123456789" ob = String(arr, 5, 4) assert ob == "5678" |
| You are visitor 01402520 — 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. |