| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,39 +1,53 @@ | |||
| 1 | 1 | # -*- coding: utf-8 -*- | |
| 2 | 2 | ||
| 3 | 3 | """Test conversions using codecs from client python code""" | |
| 4 | - import clr | ||
| 5 | - import System | ||
| 4 | + | ||
| 6 | 5 | import pytest | |
| 7 | 6 | import Python.Runtime | |
| 7 | + import Python.Test as Test | ||
| 8 | 8 | from Python.Test import ListConversionTester, ListMember, CodecResetter | |
| 9 | 9 | ||
| 10 | - class int_iterable(): | ||
| 10 | + | ||
| 11 | + @pytest.fixture(autouse=True) | ||
| 12 | + def reset(): | ||
| 13 | + yield | ||
| 14 | + CodecResetter.Reset() | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + class int_iterable: | ||
| 11 | 18 | def __init__(self): | |
| 12 | 19 | self.counter = 0 | |
| 20 | + | ||
| 13 | 21 | def __iter__(self): | |
| 14 | 22 | return self | |
| 23 | + | ||
| 15 | 24 | def __next__(self): | |
| 16 | 25 | if self.counter == 3: | |
| 17 | 26 | raise StopIteration | |
| 18 | 27 | self.counter = self.counter + 1 | |
| 19 | 28 | return self.counter | |
| 20 | 29 | ||
| 21 | - class obj_iterable(): | ||
| 30 | + | ||
| 31 | + class obj_iterable: | ||
| 22 | 32 | def __init__(self): | |
| 23 | 33 | self.counter = 0 | |
| 34 | + | ||
| 24 | 35 | def __iter__(self): | |
| 25 | 36 | return self | |
| 37 | + | ||
| 26 | 38 | def __next__(self): | |
| 27 | 39 | if self.counter == 3: | |
| 28 | 40 | raise StopIteration | |
| 29 | 41 | self.counter = self.counter + 1 | |
| 30 | 42 | return ListMember(self.counter, "Number " + str(self.counter)) | |
| 31 | 43 | ||
| 44 | + | ||
| 32 | 45 | def test_iterable(): | |
| 33 | - """Test that a python iterable can be passed into a function that takes an IEnumerable<object>""" | ||
| 46 | + """Test that a python iterable can be passed into a function that takes an | ||
| 47 | + IEnumerable<object>""" | ||
| 34 | 48 | ||
| 35 | - #Python.Runtime.Codecs.ListDecoder.Register() | ||
| 36 | - #Python.Runtime.Codecs.SequenceDecoder.Register() | ||
| 49 | + # Python.Runtime.Codecs.ListDecoder.Register() | ||
| 50 | + # Python.Runtime.Codecs.SequenceDecoder.Register() | ||
| 37 | 51 | Python.Runtime.Codecs.IterableDecoder.Register() | |
| 38 | 52 | ob = ListConversionTester() | |
| 39 | 53 | ||
@@ -43,28 +57,58 @@ def test_iterable(): | |||
| 43 | 57 | iterable2 = obj_iterable() | |
| 44 | 58 | assert 3 == ob.GetLength2(iterable2) | |
| 45 | 59 | ||
| 46 | - CodecResetter.Reset() | ||
| 47 | 60 | ||
| 48 | 61 | def test_sequence(): | |
| 49 | 62 | Python.Runtime.Codecs.SequenceDecoder.Register() | |
| 50 | 63 | ob = ListConversionTester() | |
| 51 | 64 | ||
| 52 | - tup = (1,2,3) | ||
| 65 | + tup = (1, 2, 3) | ||
| 53 | 66 | assert 3 == ob.GetLength(tup) | |
| 54 | 67 | ||
| 55 | 68 | tup2 = (ListMember(1, "one"), ListMember(2, "two"), ListMember(3, "three")) | |
| 56 | 69 | assert 3 == ob.GetLength(tup2) | |
| 57 | 70 | ||
| 58 | - CodecResetter.Reset() | ||
| 59 | 71 | ||
| 60 | 72 | def test_list(): | |
| 61 | 73 | Python.Runtime.Codecs.SequenceDecoder.Register() | |
| 62 | 74 | ob = ListConversionTester() | |
| 63 | 75 | ||
| 64 | - l = [1,2,3] | ||
| 76 | + l = [1, 2, 3] | ||
| 65 | 77 | assert 3 == ob.GetLength(l) | |
| 66 | 78 | ||
| 67 | 79 | l2 = [ListMember(1, "one"), ListMember(2, "two"), ListMember(3, "three")] | |
| 68 | 80 | assert 3 == ob.GetLength(l2) | |
| 69 | 81 | ||
| 70 | - CodecResetter.Reset() | ||
| 82 | + | ||
| 83 | + def test_enum(): | ||
| 84 | + Python.Runtime.PyObjectConversions.RegisterEncoder( | ||
| 85 | + Python.Runtime.Codecs.EnumPyIntCodec.Instance | ||
| 86 | + ) | ||
| 87 | + | ||
| 88 | + assert Test.ByteEnum.Zero == 0 | ||
| 89 | + assert Test.ByteEnum.One == 1 | ||
| 90 | + assert Test.ByteEnum.Two == 2 | ||
| 91 | + assert Test.SByteEnum.Zero == 0 | ||
| 92 | + assert Test.SByteEnum.One == 1 | ||
| 93 | + assert Test.SByteEnum.Two == 2 | ||
| 94 | + assert Test.ShortEnum.Zero == 0 | ||
| 95 | + assert Test.ShortEnum.One == 1 | ||
| 96 | + assert Test.ShortEnum.Two == 2 | ||
| 97 | + assert Test.UShortEnum.Zero == 0 | ||
| 98 | + assert Test.UShortEnum.One == 1 | ||
| 99 | + assert Test.UShortEnum.Two == 2 | ||
| 100 | + assert Test.IntEnum.Zero == 0 | ||
| 101 | + assert Test.IntEnum.One == 1 | ||
| 102 | + assert Test.IntEnum.Two == 2 | ||
| 103 | + assert Test.UIntEnum.Zero == 0 | ||
| 104 | + assert Test.UIntEnum.One == 1 | ||
| 105 | + assert Test.UIntEnum.Two == 2 | ||
| 106 | + assert Test.LongEnum.Zero == 0 | ||
| 107 | + assert Test.LongEnum.One == 1 | ||
| 108 | + assert Test.LongEnum.Two == 2 | ||
| 109 | + assert Test.ULongEnum.Zero == 0 | ||
| 110 | + assert Test.ULongEnum.One == 1 | ||
| 111 | + assert Test.ULongEnum.Two == 2 | ||
| 112 | + assert Test.LongEnum.Max == 9223372036854775807 | ||
| 113 | + assert Test.LongEnum.Min == -9223372036854775808 | ||
| 114 | + assert int(Test.ULongEnum.Max) == 18446744073709551615 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments