How to use accepts method in gabbi

Best Python code snippet using gabbi_python

testSignature.py

Source:testSignature.py Github

copy

Full Screen

...20class TestSignature(unittest.TestCase):21 version = PFAVersion(0, 8, 1)22 def typeEquality(self, x, y):23 if isinstance(x, AvroType) and isinstance(y, AvroType):24 return x.accepts(y) and y.accepts(x)25 elif isinstance(x, FcnType) and isinstance(y, FcnType):26 return all(xt.accepts(yt) and yt.accepts(xt) for xt, yt in zip(x.params, y.params)) and x.ret.accepts(y.ret) and y.ret.accepts(x.ret)27 else:28 return False29 def matches(self, x, y):30 if x is None and y is None:31 return True32 elif x is None or y is None:33 return False34 else:35 (dummy, xparams, xret) = x36 (yparams, yret) = y37 return all(self.typeEquality(xp, yp) for xp, yp in zip(xparams, yparams)) and self.typeEquality(xret, yret)38 39 def testPassThroughExactParameterMatches(self):40 self.assertTrue(self.matches(Sig([{"x": P.Null()}], P.Null()).accepts([AvroNull()], self.version), ([AvroNull()], AvroNull())))41 self.assertTrue(self.matches(Sig([{"x": P.Int()}], P.Null()).accepts([AvroInt()], self.version), ([AvroInt()], AvroNull())))42 self.assertTrue(self.matches(Sig([{"x": P.Long()}], P.Null()).accepts([AvroLong()], self.version), ([AvroLong()], AvroNull())))43 self.assertTrue(self.matches(Sig([{"x": P.Float()}], P.Null()).accepts([AvroFloat()], self.version), ([AvroFloat()], AvroNull())))44 self.assertTrue(self.matches(Sig([{"x": P.Double()}], P.Null()).accepts([AvroDouble()], self.version), ([AvroDouble()], AvroNull())))45 self.assertTrue(self.matches(Sig([{"x": P.Bytes()}], P.Null()).accepts([AvroBytes()], self.version), ([AvroBytes()], AvroNull())))46 self.assertTrue(self.matches(Sig([{"x": P.String()}], P.Null()).accepts([AvroString()], self.version), ([AvroString()], AvroNull())))47 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Int())}], P.Null()).accepts([AvroArray(AvroInt())], self.version), ([AvroArray(AvroInt())], AvroNull())))48 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Int())}], P.Null()).accepts([AvroMap(AvroInt())], self.version), ([AvroMap(AvroInt())], AvroNull())))49 self.assertTrue(self.matches(Sig([{"x": P.Union([P.Int()])}], P.Null()).accepts([AvroUnion([AvroInt()])], self.version), ([AvroUnion([AvroInt()])], AvroNull())))50 self.assertTrue(self.matches(Sig([{"x": P.Fixed(10)}], P.Null()).accepts([AvroFixed(10, "MyFixed")], self.version), ([AvroFixed(10, "MyFixed")], AvroNull())))51 self.assertTrue(self.matches(Sig([{"x": P.Fixed(10, "MyFixed")}], P.Null()).accepts([AvroFixed(10, "MyFixed")], self.version), ([AvroFixed(10, "MyFixed")], AvroNull())))52 self.assertTrue(self.matches(Sig([{"x": P.Enum(["one", "two", "three"])}], P.Null()).accepts([AvroEnum(["one", "two", "three"], "MyEnum")], self.version), ([AvroEnum(["one", "two", "three"], "MyEnum")], AvroNull())))53 self.assertTrue(self.matches(Sig([{"x": P.Enum(["one", "two", "three"], "MyEnum")}], P.Null()).accepts([AvroEnum(["one", "two", "three"], "MyEnum")], self.version), ([AvroEnum(["one", "two", "three"], "MyEnum")], AvroNull())))54 self.assertTrue(self.matches(Sig([{"x": P.Record({"one": P.Int()})}], P.Null()).accepts([AvroRecord([AvroField("one", AvroInt())], "MyRecord")], self.version), ([AvroRecord([AvroField("one", AvroInt())], "MyRecord")], AvroNull())))55 self.assertTrue(self.matches(Sig([{"x": P.Record({"one": P.Int()}, "MyRecord")}], P.Null()).accepts([AvroRecord([AvroField("one", AvroInt())], "MyRecord")], self.version), ([AvroRecord([AvroField("one", AvroInt())], "MyRecord")], AvroNull())))56 def testNotMatchAntiPatterns(self):57 self.assertTrue(self.matches(Sig([{"x": P.Null()}], P.Null()).accepts([AvroInt()], self.version), None))58 self.assertTrue(self.matches(Sig([{"x": P.Int()}], P.Null()).accepts([AvroLong()], self.version), None))59 self.assertTrue(self.matches(Sig([{"x": P.Long()}], P.Null()).accepts([AvroFloat()], self.version), None))60 self.assertTrue(self.matches(Sig([{"x": P.Float()}], P.Null()).accepts([AvroDouble()], self.version), None))61 self.assertTrue(self.matches(Sig([{"x": P.Double()}], P.Null()).accepts([AvroBytes()], self.version), None))62 self.assertTrue(self.matches(Sig([{"x": P.Bytes()}], P.Null()).accepts([AvroString()], self.version), None))63 self.assertTrue(self.matches(Sig([{"x": P.String()}], P.Null()).accepts([AvroArray(AvroInt())], self.version), None))64 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Int())}], P.Null()).accepts([AvroMap(AvroInt())], self.version), None))65 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Int())}], P.Null()).accepts([AvroUnion([AvroInt()])], self.version), None))66 self.assertTrue(self.matches(Sig([{"x": P.Union([P.Int()])}], P.Null()).accepts([AvroFixed(10, "MyFixed")], self.version), None))67 self.assertTrue(self.matches(Sig([{"x": P.Fixed(10, "YourFixed")}], P.Null()).accepts([AvroFixed(10, "MyFixed")], self.version), None))68 self.assertTrue(self.matches(Sig([{"x": P.Fixed(10)}], P.Null()).accepts([AvroEnum(["one", "two", "three"], "MyEnum")], self.version), None))69 self.assertTrue(self.matches(Sig([{"x": P.Enum(["one", "two", "three"], "YourEnum")}], P.Null()).accepts([AvroEnum(["one", "two", "three"], "MyEnum")], self.version), None))70 self.assertTrue(self.matches(Sig([{"x": P.Enum(["one", "two", "three"])}], P.Null()).accepts([AvroRecord([AvroField("one", AvroInt())], "MyRecord")], self.version), None))71 self.assertTrue(self.matches(Sig([{"x": P.Record({"one": P.Int()}, "YourRecord")}], P.Null()).accepts([AvroRecord([AvroField("one", AvroInt())], "MyRecord")], self.version), None))72 self.assertTrue(self.matches(Sig([{"x": P.Record({"one": P.Int()})}], P.Null()).accepts([AvroNull()], self.version), None))73 def testPromoteNumbers(self):74 self.assertTrue(self.matches(Sig([{"x": P.Int()}], P.Null()).accepts([AvroInt()], self.version), ([AvroInt()], AvroNull())))75 self.assertTrue(self.matches(Sig([{"x": P.Int()}], P.Null()).accepts([AvroLong()], self.version), None))76 self.assertTrue(self.matches(Sig([{"x": P.Int()}], P.Null()).accepts([AvroFloat()], self.version), None))77 self.assertTrue(self.matches(Sig([{"x": P.Int()}], P.Null()).accepts([AvroDouble()], self.version), None))78 self.assertTrue(self.matches(Sig([{"x": P.Long()}], P.Null()).accepts([AvroInt()], self.version), ([AvroLong()], AvroNull())))79 self.assertTrue(self.matches(Sig([{"x": P.Long()}], P.Null()).accepts([AvroLong()], self.version), ([AvroLong()], AvroNull())))80 self.assertTrue(self.matches(Sig([{"x": P.Long()}], P.Null()).accepts([AvroFloat()], self.version), None))81 self.assertTrue(self.matches(Sig([{"x": P.Long()}], P.Null()).accepts([AvroDouble()], self.version), None))82 self.assertTrue(self.matches(Sig([{"x": P.Float()}], P.Null()).accepts([AvroInt()], self.version), ([AvroFloat()], AvroNull())))83 self.assertTrue(self.matches(Sig([{"x": P.Float()}], P.Null()).accepts([AvroLong()], self.version), ([AvroFloat()], AvroNull())))84 self.assertTrue(self.matches(Sig([{"x": P.Float()}], P.Null()).accepts([AvroFloat()], self.version), ([AvroFloat()], AvroNull())))85 self.assertTrue(self.matches(Sig([{"x": P.Float()}], P.Null()).accepts([AvroDouble()], self.version), None))86 self.assertTrue(self.matches(Sig([{"x": P.Double()}], P.Null()).accepts([AvroInt()], self.version), ([AvroDouble()], AvroNull())))87 self.assertTrue(self.matches(Sig([{"x": P.Double()}], P.Null()).accepts([AvroLong()], self.version), ([AvroDouble()], AvroNull())))88 self.assertTrue(self.matches(Sig([{"x": P.Double()}], P.Null()).accepts([AvroDouble()], self.version), ([AvroDouble()], AvroNull())))89 self.assertTrue(self.matches(Sig([{"x": P.Double()}], P.Null()).accepts([AvroDouble()], self.version), ([AvroDouble()], AvroNull())))90 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Int())}], P.Null()).accepts([AvroArray(AvroInt())], self.version), ([AvroArray(AvroInt())], AvroNull())))91 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Int())}], P.Null()).accepts([AvroArray(AvroLong())], self.version), None))92 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Int())}], P.Null()).accepts([AvroArray(AvroFloat())], self.version), None))93 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Int())}], P.Null()).accepts([AvroArray(AvroDouble())], self.version), None))94 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Long())}], P.Null()).accepts([AvroArray(AvroInt())], self.version), ([AvroArray(AvroLong())], AvroNull())))95 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Long())}], P.Null()).accepts([AvroArray(AvroLong())], self.version), ([AvroArray(AvroLong())], AvroNull())))96 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Long())}], P.Null()).accepts([AvroArray(AvroFloat())], self.version), None))97 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Long())}], P.Null()).accepts([AvroArray(AvroDouble())], self.version), None))98 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Float())}], P.Null()).accepts([AvroArray(AvroInt())], self.version), ([AvroArray(AvroFloat())], AvroNull())))99 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Float())}], P.Null()).accepts([AvroArray(AvroLong())], self.version), ([AvroArray(AvroFloat())], AvroNull())))100 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Float())}], P.Null()).accepts([AvroArray(AvroFloat())], self.version), ([AvroArray(AvroFloat())], AvroNull())))101 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Float())}], P.Null()).accepts([AvroArray(AvroDouble())], self.version), None))102 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Double())}], P.Null()).accepts([AvroArray(AvroInt())], self.version), ([AvroArray(AvroDouble())], AvroNull())))103 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Double())}], P.Null()).accepts([AvroArray(AvroLong())], self.version), ([AvroArray(AvroDouble())], AvroNull())))104 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Double())}], P.Null()).accepts([AvroArray(AvroDouble())], self.version), ([AvroArray(AvroDouble())], AvroNull())))105 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Double())}], P.Null()).accepts([AvroArray(AvroDouble())], self.version), ([AvroArray(AvroDouble())], AvroNull())))106 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Int())}], P.Null()).accepts([AvroMap(AvroInt())], self.version), ([AvroMap(AvroInt())], AvroNull())))107 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Int())}], P.Null()).accepts([AvroMap(AvroLong())], self.version), None))108 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Int())}], P.Null()).accepts([AvroMap(AvroFloat())], self.version), None))109 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Int())}], P.Null()).accepts([AvroMap(AvroDouble())], self.version), None))110 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Long())}], P.Null()).accepts([AvroMap(AvroInt())], self.version), ([AvroMap(AvroLong())], AvroNull())))111 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Long())}], P.Null()).accepts([AvroMap(AvroLong())], self.version), ([AvroMap(AvroLong())], AvroNull())))112 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Long())}], P.Null()).accepts([AvroMap(AvroFloat())], self.version), None))113 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Long())}], P.Null()).accepts([AvroMap(AvroDouble())], self.version), None))114 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Float())}], P.Null()).accepts([AvroMap(AvroInt())], self.version), ([AvroMap(AvroFloat())], AvroNull())))115 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Float())}], P.Null()).accepts([AvroMap(AvroLong())], self.version), ([AvroMap(AvroFloat())], AvroNull())))116 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Float())}], P.Null()).accepts([AvroMap(AvroFloat())], self.version), ([AvroMap(AvroFloat())], AvroNull())))117 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Float())}], P.Null()).accepts([AvroMap(AvroDouble())], self.version), None))118 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Double())}], P.Null()).accepts([AvroMap(AvroInt())], self.version), ([AvroMap(AvroDouble())], AvroNull())))119 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Double())}], P.Null()).accepts([AvroMap(AvroLong())], self.version), ([AvroMap(AvroDouble())], AvroNull())))120 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Double())}], P.Null()).accepts([AvroMap(AvroDouble())], self.version), ([AvroMap(AvroDouble())], AvroNull())))121 self.assertTrue(self.matches(Sig([{"x": P.Map(P.Double())}], P.Null()).accepts([AvroMap(AvroDouble())], self.version), ([AvroMap(AvroDouble())], AvroNull())))122 def testLooselyMatchFunctionReferences(self):123 self.assertTrue(self.matches(Sig([{"x": P.Fcn([P.Long()], P.Long())}], P.Null()).accepts([FcnType([AvroLong()], AvroLong())], self.version), ([FcnType([AvroLong()], AvroLong())], AvroNull())))124 self.assertTrue(self.matches(Sig([{"x": P.Fcn([P.Long()], P.Long())}], P.Null()).accepts([FcnType([AvroLong()], AvroInt())], self.version), ([FcnType([AvroLong()], AvroInt())], AvroNull())))125 self.assertTrue(self.matches(Sig([{"x": P.Fcn([P.Long()], P.Long())}], P.Null()).accepts([FcnType([AvroDouble()], AvroLong())], self.version), ([FcnType([AvroDouble()], AvroLong())], AvroNull())))126 def testMatchWildcards(self):127 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Wildcard("A")).accepts([AvroNull()], self.version), ([AvroNull()], AvroNull())))128 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Wildcard("A")).accepts([AvroInt()], self.version), ([AvroInt()], AvroInt())))129 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Wildcard("A")).accepts([AvroLong()], self.version), ([AvroLong()], AvroLong())))130 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Wildcard("A")).accepts([AvroFloat()], self.version), ([AvroFloat()], AvroFloat())))131 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Wildcard("A")).accepts([AvroDouble()], self.version), ([AvroDouble()], AvroDouble())))132 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Wildcard("A")).accepts([AvroBytes()], self.version), ([AvroBytes()], AvroBytes())))133 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Wildcard("A")).accepts([AvroString()], self.version), ([AvroString()], AvroString())))134 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Wildcard("A")).accepts([AvroArray(AvroInt())], self.version), ([AvroArray(AvroInt())], AvroArray(AvroInt()))))135 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Wildcard("A")).accepts([AvroMap(AvroInt())], self.version), ([AvroMap(AvroInt())], AvroMap(AvroInt()))))136 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Wildcard("A")).accepts([AvroUnion([AvroInt()])], self.version), ([AvroUnion([AvroInt()])], AvroUnion([AvroInt()]))))137 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Wildcard("A")).accepts([AvroFixed(10, "MyFixed")], self.version), ([AvroFixed(10, "MyFixed")], AvroFixed(10, "MyFixed"))))138 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Wildcard("A")).accepts([AvroEnum(["one", "two", "three"], "MyEnum")], self.version), ([AvroEnum(["one", "two", "three"], "MyEnum")], AvroEnum(["one", "two", "three"], "MyEnum"))))139 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Wildcard("A")).accepts([AvroRecord([AvroField("one", AvroInt())], "MyRecord")], self.version), ([AvroRecord([AvroField("one", AvroInt())], "MyRecord")], AvroRecord([AvroField("one", AvroInt())], "MyRecord"))))140 def testMatchNestedWildcards(self):141 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Wildcard("A"))}], P.Wildcard("A")).accepts([AvroArray(AvroNull())], self.version), ([AvroArray(AvroNull())], AvroNull())))142 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Wildcard("A"))}], P.Wildcard("A")).accepts([AvroArray(AvroInt())], self.version), ([AvroArray(AvroInt())], AvroInt())))143 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Wildcard("A"))}], P.Wildcard("A")).accepts([AvroArray(AvroLong())], self.version), ([AvroArray(AvroLong())], AvroLong())))144 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Wildcard("A"))}], P.Wildcard("A")).accepts([AvroArray(AvroFloat())], self.version), ([AvroArray(AvroFloat())], AvroFloat())))145 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Wildcard("A"))}], P.Wildcard("A")).accepts([AvroArray(AvroDouble())], self.version), ([AvroArray(AvroDouble())], AvroDouble())))146 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Wildcard("A"))}], P.Wildcard("A")).accepts([AvroArray(AvroBytes())], self.version), ([AvroArray(AvroBytes())], AvroBytes())))147 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Wildcard("A"))}], P.Wildcard("A")).accepts([AvroArray(AvroString())], self.version), ([AvroArray(AvroString())], AvroString())))148 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Wildcard("A"))}], P.Wildcard("A")).accepts([AvroArray(AvroArray(AvroInt()))], self.version), ([AvroArray(AvroArray(AvroInt()))], AvroArray(AvroInt()))))149 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Wildcard("A"))}], P.Wildcard("A")).accepts([AvroArray(AvroMap(AvroInt()))], self.version), ([AvroArray(AvroMap(AvroInt()))], AvroMap(AvroInt()))))150 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Wildcard("A"))}], P.Wildcard("A")).accepts([AvroArray(AvroUnion([AvroInt()]))], self.version), ([AvroArray(AvroUnion([AvroInt()]))], AvroUnion([AvroInt()]))))151 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Wildcard("A"))}], P.Wildcard("A")).accepts([AvroArray(AvroFixed(10, "MyFixed"))], self.version), ([AvroArray(AvroFixed(10, "MyFixed"))], AvroFixed(10, "MyFixed"))))152 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Wildcard("A"))}], P.Wildcard("A")).accepts([AvroArray(AvroEnum(["one", "two", "three"], "MyEnum"))], self.version), ([AvroArray(AvroEnum(["one", "two", "three"], "MyEnum"))], AvroEnum(["one", "two", "three"], "MyEnum"))))153 self.assertTrue(self.matches(Sig([{"x": P.Array(P.Wildcard("A"))}], P.Wildcard("A")).accepts([AvroArray(AvroRecord([AvroField("one", AvroInt())], "MyRecord"))], self.version), ([AvroArray(AvroRecord([AvroField("one", AvroInt())], "MyRecord"))], AvroRecord([AvroField("one", AvroInt())], "MyRecord"))))154 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Array(P.Wildcard("A"))).accepts([AvroNull()], self.version), ([AvroNull()], AvroArray(AvroNull()))))155 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Array(P.Wildcard("A"))).accepts([AvroInt()], self.version), ([AvroInt()], AvroArray(AvroInt()))))156 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Array(P.Wildcard("A"))).accepts([AvroLong()], self.version), ([AvroLong()], AvroArray(AvroLong()))))157 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Array(P.Wildcard("A"))).accepts([AvroFloat()], self.version), ([AvroFloat()], AvroArray(AvroFloat()))))158 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Array(P.Wildcard("A"))).accepts([AvroDouble()], self.version), ([AvroDouble()], AvroArray(AvroDouble()))))159 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Array(P.Wildcard("A"))).accepts([AvroBytes()], self.version), ([AvroBytes()], AvroArray(AvroBytes()))))160 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Array(P.Wildcard("A"))).accepts([AvroString()], self.version), ([AvroString()], AvroArray(AvroString()))))161 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Array(P.Wildcard("A"))).accepts([AvroArray(AvroInt())], self.version), ([AvroArray(AvroInt())], AvroArray(AvroArray(AvroInt())))))162 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Array(P.Wildcard("A"))).accepts([AvroMap(AvroInt())], self.version), ([AvroMap(AvroInt())], AvroArray(AvroMap(AvroInt())))))163 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Array(P.Wildcard("A"))).accepts([AvroUnion([AvroInt()])], self.version), ([AvroUnion([AvroInt()])], AvroArray(AvroUnion([AvroInt()])))))164 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Array(P.Wildcard("A"))).accepts([AvroFixed(10, "MyFixed")], self.version), ([AvroFixed(10, "MyFixed")], AvroArray(AvroFixed(10, "MyFixed")))))165 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Array(P.Wildcard("A"))).accepts([AvroEnum(["one", "two", "three"], "MyEnum")], self.version), ([AvroEnum(["one", "two", "three"], "MyEnum")], AvroArray(AvroEnum(["one", "two", "three"], "MyEnum")))))166 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A")}], P.Array(P.Wildcard("A"))).accepts([AvroRecord([AvroField("one", AvroInt())], "MyRecord")], self.version), ([AvroRecord([AvroField("one", AvroInt())], "MyRecord")], AvroArray(AvroRecord([AvroField("one", AvroInt())], "MyRecord")))))167 def testUseWildcardsToNormalizeNumericalTypes(self):168 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroInt(), AvroInt()], self.version), ([AvroInt(), AvroInt()], AvroNull())))169 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroInt(), AvroLong()], self.version), ([AvroLong(), AvroLong()], AvroNull())))170 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroInt(), AvroFloat()], self.version), ([AvroFloat(), AvroFloat()], AvroNull())))171 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroInt(), AvroDouble()], self.version), ([AvroDouble(), AvroDouble()], AvroNull())))172 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroLong(), AvroInt()], self.version), ([AvroLong(), AvroLong()], AvroNull())))173 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroLong(), AvroLong()], self.version), ([AvroLong(), AvroLong()], AvroNull())))174 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroLong(), AvroFloat()], self.version), ([AvroFloat(), AvroFloat()], AvroNull())))175 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroLong(), AvroDouble()], self.version), ([AvroDouble(), AvroDouble()], AvroNull())))176 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroFloat(), AvroInt()], self.version), ([AvroFloat(), AvroFloat()], AvroNull())))177 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroFloat(), AvroLong()], self.version), ([AvroFloat(), AvroFloat()], AvroNull())))178 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroFloat(), AvroFloat()], self.version), ([AvroFloat(), AvroFloat()], AvroNull())))179 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroFloat(), AvroDouble()], self.version), ([AvroDouble(), AvroDouble()], AvroNull())))180 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroDouble(), AvroInt()], self.version), ([AvroDouble(), AvroDouble()], AvroNull())))181 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroDouble(), AvroLong()], self.version), ([AvroDouble(), AvroDouble()], AvroNull())))182 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroDouble(), AvroFloat()], self.version), ([AvroDouble(), AvroDouble()], AvroNull())))183 self.assertTrue(self.matches(Sig([{"x": P.Wildcard("A", set([AvroInt(), AvroLong(), AvroFloat(), AvroDouble()]))}, {"y": P.Wildcard("A")}], P.Null()).accepts([AvroDouble(), AvroDouble()], self.version), ([AvroDouble(), AvroDouble()], AvroNull())))184 def testMatchWildRecords(self):185 self.assertTrue(self.matches(Sig([{"x": P.WildRecord("A", {"one": P.Int()})}], P.Wildcard("A")).accepts([AvroRecord([AvroField("one", AvroInt())], "MyRecord")], self.version), ([AvroRecord([AvroField("one", AvroInt())], "MyRecord")], AvroRecord([AvroField("one", AvroInt())], "MyRecord"))))186 self.assertTrue(self.matches(Sig([{"x": P.WildRecord("A", {"one": P.Int()})}], P.Wildcard("A")).accepts([AvroRecord([AvroField("one", AvroInt()), AvroField("two", AvroString())], "MyRecord")], self.version), ([AvroRecord([AvroField("one", AvroInt()), AvroField("two", AvroString())], "MyRecord")], AvroRecord([AvroField("one", AvroInt()), AvroField("two", AvroString())], "MyRecord"))))187 self.assertTrue(self.matches(Sig([{"x": P.WildRecord("A", {"one": P.String()})}], P.Wildcard("A")).accepts([AvroRecord([AvroField("one", AvroInt()), AvroField("two", AvroString())], "MyRecord")], self.version), None))188 self.assertTrue(self.matches(Sig([{"x": P.WildRecord("A", {"one": P.Double()})}], P.Wildcard("A")).accepts([AvroRecord([AvroField("one", AvroInt()), AvroField("two", AvroString())], "MyRecord")], self.version), None))189 self.assertTrue(self.matches(Sig([{"x": P.WildRecord("A", {"one": P.Int()})}], P.Wildcard("A")).accepts([AvroRecord([AvroField("uno", AvroInt()), AvroField("two", AvroString())], "MyRecord")], self.version), None))190if __name__ == "__main__":...

Full Screen

Full Screen

testDatatype.py

Source:testDatatype.py Github

copy

Full Screen

...16import unittest17from poie.datatype import *18class TestDataType(unittest.TestCase):19 def testPromoteNumbers(self):20 self.assertTrue(AvroInt().accepts(AvroInt()))21 self.assertTrue(AvroInt().accepts(AvroInt()))22 self.assertTrue(AvroLong().accepts(AvroInt()))23 self.assertTrue(AvroFloat().accepts(AvroInt()))24 self.assertTrue(AvroDouble().accepts(AvroInt()))25 self.assertTrue(AvroLong().accepts(AvroLong()))26 self.assertTrue(AvroFloat().accepts(AvroLong()))27 self.assertTrue(AvroDouble().accepts(AvroLong()))28 self.assertTrue(AvroFloat().accepts(AvroFloat()))29 self.assertTrue(AvroDouble().accepts(AvroFloat()))30 self.assertTrue(AvroDouble().accepts(AvroDouble()))31 self.assertFalse(AvroInt().accepts(AvroLong()))32 self.assertFalse(AvroInt().accepts(AvroFloat()))33 self.assertFalse(AvroInt().accepts(AvroDouble()))34 self.assertFalse(AvroLong().accepts(AvroFloat()))35 self.assertFalse(AvroLong().accepts(AvroDouble()))36 self.assertFalse(AvroFloat().accepts(AvroDouble()))37 def testPromoteNumbersTypeVariantArray(self):38 self.assertTrue(AvroArray(AvroInt()).accepts(AvroArray(AvroInt())))39 self.assertTrue(AvroArray(AvroLong()).accepts(AvroArray(AvroInt())))40 self.assertTrue(AvroArray(AvroFloat()).accepts(AvroArray(AvroInt())))41 self.assertTrue(AvroArray(AvroDouble()).accepts(AvroArray(AvroInt())))42 self.assertTrue(AvroArray(AvroLong()).accepts(AvroArray(AvroLong())))43 self.assertTrue(AvroArray(AvroFloat()).accepts(AvroArray(AvroLong())))44 self.assertTrue(AvroArray(AvroDouble()).accepts(AvroArray(AvroLong())))45 self.assertTrue(AvroArray(AvroFloat()).accepts(AvroArray(AvroFloat())))46 self.assertTrue(AvroArray(AvroDouble()).accepts(AvroArray(AvroFloat())))47 self.assertTrue(AvroArray(AvroDouble()).accepts(AvroArray(AvroDouble())))48 self.assertFalse(AvroArray(AvroInt()).accepts(AvroArray(AvroLong())))49 self.assertFalse(AvroArray(AvroInt()).accepts(AvroArray(AvroFloat())))50 self.assertFalse(AvroArray(AvroInt()).accepts(AvroArray(AvroDouble())))51 self.assertFalse(AvroArray(AvroLong()).accepts(AvroArray(AvroFloat())))52 self.assertFalse(AvroArray(AvroLong()).accepts(AvroArray(AvroDouble())))53 self.assertFalse(AvroArray(AvroFloat()).accepts(AvroArray(AvroDouble())))54 def testPromoteNumbersTypeVariantMap(self):55 self.assertTrue(AvroMap(AvroInt()).accepts(AvroMap(AvroInt())))56 self.assertTrue(AvroMap(AvroLong()).accepts(AvroMap(AvroInt())))57 self.assertTrue(AvroMap(AvroFloat()).accepts(AvroMap(AvroInt())))58 self.assertTrue(AvroMap(AvroDouble()).accepts(AvroMap(AvroInt())))59 self.assertTrue(AvroMap(AvroLong()).accepts(AvroMap(AvroLong())))60 self.assertTrue(AvroMap(AvroFloat()).accepts(AvroMap(AvroLong())))61 self.assertTrue(AvroMap(AvroDouble()).accepts(AvroMap(AvroLong())))62 self.assertTrue(AvroMap(AvroFloat()).accepts(AvroMap(AvroFloat())))63 self.assertTrue(AvroMap(AvroDouble()).accepts(AvroMap(AvroFloat())))64 self.assertTrue(AvroMap(AvroDouble()).accepts(AvroMap(AvroDouble())))65 self.assertFalse(AvroMap(AvroInt()).accepts(AvroMap(AvroLong())))66 self.assertFalse(AvroMap(AvroInt()).accepts(AvroMap(AvroFloat())))67 self.assertFalse(AvroMap(AvroInt()).accepts(AvroMap(AvroDouble())))68 self.assertFalse(AvroMap(AvroLong()).accepts(AvroMap(AvroFloat())))69 self.assertFalse(AvroMap(AvroLong()).accepts(AvroMap(AvroDouble())))70 self.assertFalse(AvroMap(AvroFloat()).accepts(AvroMap(AvroDouble())))71 def testPromoteNumbersInRecord(self):72 self.assertTrue(AvroRecord([AvroField("one", AvroInt())], name="One").accepts(AvroRecord([AvroField("one", AvroInt())], name="One")))73 self.assertTrue(AvroRecord([AvroField("one", AvroLong())], name="One").accepts(AvroRecord([AvroField("one", AvroInt())], name="One")))74 self.assertTrue(AvroRecord([AvroField("one", AvroFloat())], name="One").accepts(AvroRecord([AvroField("one", AvroInt())], name="One")))75 self.assertTrue(AvroRecord([AvroField("one", AvroDouble())], name="One").accepts(AvroRecord([AvroField("one", AvroInt())], name="One")))76 self.assertTrue(AvroRecord([AvroField("one", AvroLong())], name="One").accepts(AvroRecord([AvroField("one", AvroLong())], name="One")))77 self.assertTrue(AvroRecord([AvroField("one", AvroFloat())], name="One").accepts(AvroRecord([AvroField("one", AvroLong())], name="One")))78 self.assertTrue(AvroRecord([AvroField("one", AvroDouble())], name="One").accepts(AvroRecord([AvroField("one", AvroLong())], name="One")))79 self.assertTrue(AvroRecord([AvroField("one", AvroFloat())], name="One").accepts(AvroRecord([AvroField("one", AvroFloat())], name="One")))80 self.assertTrue(AvroRecord([AvroField("one", AvroDouble())], name="One").accepts(AvroRecord([AvroField("one", AvroFloat())], name="One")))81 self.assertTrue(AvroRecord([AvroField("one", AvroDouble())], name="One").accepts(AvroRecord([AvroField("one", AvroDouble())], name="One")))82 self.assertFalse(AvroRecord([AvroField("one", AvroInt())], name="One").accepts(AvroRecord([AvroField("one", AvroLong())], name="One")))83 self.assertFalse(AvroRecord([AvroField("one", AvroInt())], name="One").accepts(AvroRecord([AvroField("one", AvroFloat())], name="One")))84 self.assertFalse(AvroRecord([AvroField("one", AvroInt())], name="One").accepts(AvroRecord([AvroField("one", AvroDouble())], name="One")))85 self.assertFalse(AvroRecord([AvroField("one", AvroLong())], name="One").accepts(AvroRecord([AvroField("one", AvroFloat())], name="One")))86 self.assertFalse(AvroRecord([AvroField("one", AvroLong())], name="One").accepts(AvroRecord([AvroField("one", AvroDouble())], name="One")))87 self.assertFalse(AvroRecord([AvroField("one", AvroFloat())], name="One").accepts(AvroRecord([AvroField("one", AvroDouble())], name="One")))88 def testHaveTypeSafeNull(self):89 self.assertFalse(AvroNull().accepts(AvroString()))90 self.assertFalse(AvroString().accepts(AvroNull()))91 def testDistinguishBooleanFromNumbers(self):92 self.assertFalse(AvroBoolean().accepts(AvroInt()))93 self.assertFalse(AvroBoolean().accepts(AvroLong()))94 self.assertFalse(AvroBoolean().accepts(AvroFloat()))95 self.assertFalse(AvroBoolean().accepts(AvroDouble()))96 self.assertFalse(AvroInt().accepts(AvroBoolean()))97 self.assertFalse(AvroLong().accepts(AvroBoolean()))98 self.assertFalse(AvroFloat().accepts(AvroBoolean()))99 self.assertFalse(AvroDouble().accepts(AvroBoolean()))100 def testDistinguishBytesStringEnumFixed(self):101 self.assertTrue(AvroBytes().accepts(AvroBytes()))102 self.assertFalse(AvroBytes().accepts(AvroString()))103 self.assertFalse(AvroBytes().accepts(AvroEnum(["one", "two", "three"], name="One")))104 self.assertFalse(AvroBytes().accepts(AvroFixed(5, name="One")))105 self.assertFalse(AvroString().accepts(AvroBytes()))106 self.assertTrue(AvroString().accepts(AvroString()))107 self.assertFalse(AvroString().accepts(AvroEnum(["one", "two", "three"], name="One")))108 self.assertFalse(AvroString().accepts(AvroFixed(5, name="One")))109 self.assertFalse(AvroEnum(["one", "two", "three"], name="One").accepts(AvroBytes()))110 self.assertFalse(AvroEnum(["one", "two", "three"], name="One").accepts(AvroString()))111 self.assertTrue(AvroEnum(["one", "two", "three"], name="One").accepts(AvroEnum(["one", "two", "three"], name="One")))112 self.assertFalse(AvroEnum(["one", "two", "three"], name="One").accepts(AvroFixed(5, name="One")))113 self.assertFalse(AvroFixed(5, name="One").accepts(AvroBytes()))114 self.assertFalse(AvroFixed(5, name="One").accepts(AvroString()))115 self.assertFalse(AvroFixed(5, name="One").accepts(AvroEnum(["one", "two", "three"], name="One")))116 self.assertTrue(AvroFixed(5, name="One").accepts(AvroFixed(5, name="One")))117 def testResolveUnions(self):118 self.assertTrue(AvroUnion([AvroInt(), AvroString()]).accepts(AvroInt()))119 self.assertTrue(AvroUnion([AvroInt(), AvroString()]).accepts(AvroString()))120 self.assertFalse(AvroUnion([AvroInt(), AvroString()]).accepts(AvroDouble()))121 self.assertTrue(AvroUnion([AvroInt(), AvroString(), AvroNull()]).accepts(AvroUnion([AvroInt(), AvroString()])))122 self.assertTrue(AvroUnion([AvroInt(), AvroString(), AvroNull()]).accepts(AvroUnion([AvroInt(), AvroNull()])))123 def doParserTest(self, input, expected):124 found = ForwardDeclarationParser().parse([input])[input]125 self.assertTrue(found.accepts(expected) and expected.accepts(found))126 def testReadSimpleTypes(self):127 self.doParserTest('''"null"''', AvroNull())128 self.doParserTest('''"boolean"''', AvroBoolean())129 self.doParserTest('''"int"''', AvroInt())130 self.doParserTest('''"long"''', AvroLong())131 self.doParserTest('''"float"''', AvroFloat())132 self.doParserTest('''"double"''', AvroDouble())133 self.doParserTest('''"bytes"''', AvroBytes())134 self.doParserTest('''{"type": "fixed", "name": "Test", "size": 5}''', AvroFixed(5, name="Test"))135 self.doParserTest('''"string"''', AvroString())136 self.doParserTest('''{"type": "enum", "name": "Test", "symbols": ["one", "two", "three"]}''', AvroEnum(["one", "two", "three"], name="Test"))137 self.doParserTest('''{"type": "array", "items": "int"}''', AvroArray(AvroInt()))138 self.doParserTest('''{"type": "map", "values": "int"}''', AvroMap(AvroInt()))139 self.doParserTest('''{"type": "record", "name": "Test", "fields": [{"name": "one", "type": "int"}]}''', AvroRecord([AvroField("one", AvroInt())], name="Test"))140 self.doParserTest('''["string", "null"]''', AvroUnion([AvroString(), AvroNull()]))141 def testIdentifyNestedRecordDefinitions(self):142 self.maxDiff = None143 self.doParserTest(144 '''{"type": "record", "name": "Outer", "fields": [{"name": "child", "type": {"type": "record", "name": "Inner", "fields": [{"name": "child", "type": "int"}]}}]}''',145 AvroRecord([AvroField("child", AvroRecord([AvroField("child", AvroInt())], name="Inner"))], name="Outer"))146 def testResolveDependentRecordsInAnyOrder(self):147 record1 = '''{"type": "record", "name": "Outer", "fields": [{"name": "child", "type": "Inner"}]}'''148 record2 = '''{"type": "record", "name": "Inner", "fields": [{"name": "child", "type": "int"}]}'''149 expected1 = AvroRecord([AvroField("child", AvroRecord([AvroField("child", AvroInt())], name="Inner"))], name="Outer")150 expected2 = AvroRecord([AvroField("child", AvroInt())], name="Inner")151 found = ForwardDeclarationParser().parse([record1, record2])152 self.assertTrue(found[record1].accepts(expected1) and expected1.accepts(found[record1]))153 self.assertTrue(found[record2].accepts(expected2) and expected2.accepts(found[record2]))154 found = ForwardDeclarationParser().parse([record2, record1])155 self.assertTrue(found[record1].accepts(expected1) and expected1.accepts(found[record1]))156 self.assertTrue(found[record2].accepts(expected2) and expected2.accepts(found[record2]))157 def testResolveDependentRecordsWithNamespaces(self):158 record1 = '''{"type": "record", "name": "Outer", "namespace": "com.wowie", "fields": [{"name": "child", "type": "Inner"}]}'''159 record2 = '''{"type": "record", "name": "Inner", "namespace": "com.wowie", "fields": [{"name": "child", "type": "int"}]}'''160 expected1 = AvroRecord([AvroField("child", AvroRecord([AvroField("child", AvroInt())], name="Inner", namespace="com.wowie"))], name="Outer", namespace="com.wowie")161 expected2 = AvroRecord([AvroField("child", AvroInt())], name="Inner", namespace="com.wowie")162 found = ForwardDeclarationParser().parse([record1, record2])163 self.assertTrue(found[record1].accepts(expected1) and expected1.accepts(found[record1]))164 self.assertTrue(found[record2].accepts(expected2) and expected2.accepts(found[record2]))165 found = ForwardDeclarationParser().parse([record2, record1])166 self.assertTrue(found[record1].accepts(expected1) and expected1.accepts(found[record1]))167 self.assertTrue(found[record2].accepts(expected2) and expected2.accepts(found[record2]))168 def testResolveRecursivelyDefinedRecords(self):169 record1 = '''{"type": "record", "name": "Recursive", "fields": [{"name": "child", "type": ["null", "Recursive"]}]}'''170 result = ForwardDeclarationParser().parse([record1])[record1]171 x = result.field("child").avroType172 y = AvroUnion([AvroNull(), result])173 self.assertTrue(x.accepts(y) and y.accepts(x))174 def testReCallableAndAccumulateTypes(self):175 forwardDeclarationParser = ForwardDeclarationParser()176 record1 = '''{"type": "record", "name": "Outer", "fields": [{"name": "child", "type": "Inner"}]}'''177 record2 = '''{"type": "record", "name": "Inner", "fields": [{"name": "child", "type": "int"}]}'''178 record3 = '''{"type": "record", "name": "Another", "fields": [{"name": "innerChild", "type": "Inner"}]}'''179 type1 = AvroRecord([AvroField("child", AvroRecord([AvroField("child", AvroInt())], name="Inner"))], name="Outer")180 type2 = AvroRecord([AvroField("child", AvroInt())], name="Inner")181 type3 = AvroRecord([AvroField("innerChild", AvroRecord([AvroField("child", AvroInt())], name="Inner"))], name="Another")182 result1 = forwardDeclarationParser.parse([record1, record2])183 self.assertTrue(result1[record1].accepts(type1) and type1.accepts(result1[record1]))184 self.assertTrue(result1[record2].accepts(type2) and type2.accepts(result1[record2]))185 result2 = forwardDeclarationParser.parse([record3])186 self.assertTrue(result2[record3].accepts(type3) and type3.accepts(result2[record3]))187 def equivalent(x, y):188 return x.accepts(y) and y.accepts(x)189 self.assertTrue(equivalent(forwardDeclarationParser.getAvroType("Outer"), type1))190 self.assertTrue(equivalent(forwardDeclarationParser.getAvroType("Inner"), type2))191 self.assertTrue(equivalent(forwardDeclarationParser.getAvroType("Another"), type3))192 # forwardDeclarationParser.getAvroType('''"Outer"''') should be (Some(type1))193 # forwardDeclarationParser.getAvroType('''{"type": "Outer"}''') should be (Some(type1))194 # forwardDeclarationParser.getAvroType('''{"type": "array", "items": "Outer"}''') should be (Some(AvroArray(type1)))195 # forwardDeclarationParser.getAvroType('''{"type": "array", "items": "int"}''') should be (Some(AvroArray(AvroInt())))196if __name__ == "__main__":...

Full Screen

Full Screen

test_python_regex.py

Source:test_python_regex.py Github

copy

Full Screen

...8 """ Tests for python regex """9 # pylint: disable=missing-function-docstring, too-many-public-methods10 def test_with_brackets(self):11 regex = PythonRegex("a[bc]")12 self.assertTrue(regex.accepts(["a", "b"]))13 self.assertTrue(regex.accepts(["a", "c"]))14 self.assertFalse(regex.accepts(["a", "b", "c"]))15 self.assertFalse(regex.accepts(["a", "a"]))16 def test_range_in_brackets(self):17 regex = PythonRegex("a[a-z]")18 self.assertTrue(regex.accepts(["a", "a"]))19 self.assertTrue(regex.accepts(["a", "c"]))20 self.assertTrue(regex.accepts(["a", "g"]))21 self.assertTrue(regex.accepts(["a", "z"]))22 self.assertFalse(regex.accepts(["a", "b", "c"]))23 self.assertFalse(regex.accepts(["a", "A"]))24 def test_range_in_brackets_trap(self):25 regex = PythonRegex("a[a-e-z]")26 self.assertTrue(regex.accepts(["a", "a"]))27 self.assertTrue(regex.accepts(["a", "c"]))28 self.assertTrue(regex.accepts(["a", "z"]))29 self.assertTrue(regex.accepts(["a", "-"]))30 self.assertFalse(regex.accepts(["a", "y"]))31 self.assertFalse(regex.accepts(["a", "f"]))32 def test_range_in_brackets_trap2(self):33 regex = PythonRegex("[a-e-g-z]*")34 self.assertTrue(regex.accepts(["a", "-", "y"]))35 def test_range_in_brackets_trap2_bis(self):36 regex = PythonRegex(re.compile("[a-e-g-z]*"))37 self.assertTrue(regex.accepts(["a", "-", "y"]))38 def test_parenthesis(self):39 regex = PythonRegex("((a)|(b))+")40 self.assertTrue(regex.accepts(["a", "b"]))41 def test_plus(self):42 regex = PythonRegex("a+")43 self.assertFalse(regex.accepts([]))44 self.assertTrue(regex.accepts(["a"]))45 self.assertTrue(regex.accepts(["a", "a"]))46 def test_dot(self):47 regex = PythonRegex("a.")48 self.assertTrue(regex.accepts(["a", "b"]))49 self.assertTrue(regex.accepts(["a", "?"]))50 self.assertFalse(regex.accepts(["a", "\n"]))51 self.assertFalse(regex.accepts(["a"]))52 self.assertTrue(regex.accepts(["a", "|"]))53 self.assertTrue(regex.accepts(["a", "("]))54 self.assertTrue(regex.accepts(["a", ")"]))55 self.assertTrue(regex.accepts(["a", "."]))56 self.assertTrue(regex.accepts(["a", "*"]))57 self.assertTrue(regex.accepts(["a", "+"]))58 self.assertTrue(regex.accepts(["a", "$"]))59 def test_dot_spaces(self):60 regex = PythonRegex("a.")61 self.assertTrue(regex.accepts(["a", " "]))62 self.assertTrue(regex.accepts(["a", "\t"]))63 self.assertTrue(regex.accepts(["a", "\v"]))64 self.assertTrue(regex.accepts(["a", "\r"]))65 def test_simple_optional(self):66 regex = PythonRegex("ab?")67 self.assertTrue(regex.accepts(["a"]))68 self.assertTrue(regex.accepts(["a", "b"]))69 self.assertFalse(regex.accepts(["a", "a"]))70 def test_with_parenthesis_optional(self):71 regex = PythonRegex("a(bb|c)?")72 self.assertTrue(regex.accepts(["a"]))73 self.assertTrue(regex.accepts(["a", "b", "b"]))74 self.assertTrue(regex.accepts(["a", "c"]))75 self.assertFalse(regex.accepts(["a", "b"]))76 def test_escape_question_mark(self):77 regex = PythonRegex(r"ab\?")78 self.assertTrue(regex.accepts(["a", "b", "?"]))79 def test_escape_kleene_star(self):80 regex = PythonRegex(r"ab\*")81 self.assertTrue(regex.accepts(["a", "b", "*"]))82 def test_escape_plus(self):83 regex = PythonRegex(r"ab\+")84 self.assertTrue(regex.accepts(["a", "b", "+"]))85 self.assertFalse(regex.accepts(["a", "b", "\\"]))86 def test_escape_opening_bracket(self):87 regex = PythonRegex(r"a\[")88 self.assertTrue(regex.accepts(["a", "["]))89 def test_escape_closing_bracket(self):90 regex = PythonRegex(r"a\]")91 self.assertTrue(regex.accepts(["a", "]"]))92 def test_escape_backslash(self):93 regex = PythonRegex(r"a\\")94 self.assertTrue(regex.accepts(["a", "\\"]))95 def test_escape_backslash_plus(self):96 regex = PythonRegex(r"a\\+")97 self.assertTrue(regex.accepts(["a", "\\", "\\"]))98 def test_escape_backslash_opening_bracket(self):99 regex = PythonRegex(r"a\\[ab]")100 self.assertTrue(regex.accepts(["a", "\\", "a"]))101 self.assertTrue(regex.accepts(["a", "\\", "b"]))102 def test_escape_backslash_closing_bracket(self):103 regex = PythonRegex(r"a[ab\\]")104 self.assertTrue(regex.accepts(["a", "a"]))105 self.assertTrue(regex.accepts(["a", "b"]))106 self.assertTrue(regex.accepts(["a", "\\"]))107 def test_escape_backslash_question_mark(self):108 regex = PythonRegex(r"a\\?")109 self.assertTrue(regex.accepts(["a"]))110 self.assertTrue(regex.accepts(["a", "\\"]))111 self.assertFalse(regex.accepts(["a", "\\", "?"]))112 self.assertFalse(regex.accepts(["a", "\\?"]))113 def test_escape_dash_in_brackets(self):114 regex = PythonRegex(r"a[a\-]")115 self.assertTrue(regex.accepts(["a", "a"]))116 self.assertTrue(regex.accepts(["a", "-"]))117 def test_special_in_brackets_opening_parenthesis(self):118 regex = PythonRegex(r"a[a(]")119 self.assertTrue(regex.accepts(["a", "a"]))120 self.assertTrue(regex.accepts(["a", "("]))121 def test_special_in_brackets_closing_parenthesis(self):122 regex = PythonRegex(r"a[a)]")123 self.assertTrue(regex.accepts(["a", "a"]))124 self.assertTrue(regex.accepts(["a", ")"]))125 def test_special_in_brackets_kleene_star(self):126 regex = PythonRegex(r"a[a*]")127 self.assertTrue(regex.accepts(["a", "a"]))128 self.assertTrue(regex.accepts(["a", "*"]))129 self.assertFalse(regex.accepts(["a", "a", "a"]))130 def test_special_in_brackets_positive_closure(self):131 regex = PythonRegex(r"a[a+]")132 self.assertTrue(regex.accepts(["a", "a"]))133 self.assertTrue(regex.accepts(["a", "+"]))134 self.assertFalse(regex.accepts(["a", "a", "a"]))135 def test_special_in_brackets_optional(self):136 regex = PythonRegex(r"a[a?]")137 self.assertTrue(regex.accepts(["a", "a"]))138 self.assertTrue(regex.accepts(["a", "?"]))139 self.assertFalse(regex.accepts(["a"]))140 def test_shortcut_digits(self):141 regex = PythonRegex(r"a\d")142 self.assertTrue(regex.accepts(["a", "0"]))143 self.assertTrue(regex.accepts(["a", "1"]))144 def test_shortcut_digits_in_brackets(self):145 regex = PythonRegex(r"a[\da]")146 self.assertTrue(regex.accepts(["a", "0"]))147 self.assertTrue(regex.accepts(["a", "1"]))148 self.assertTrue(regex.accepts(["a", "a"]))149 def test_shortcut_spaces(self):150 regex = PythonRegex(r"a\s")151 self.assertTrue(regex.accepts(["a", " "]))152 self.assertTrue(regex.accepts(["a", "\t"]))153 def test_space(self):154 regex = PythonRegex(" ")155 self.assertTrue(regex.accepts([" "]))156 def test_shortcut_word(self):157 regex = PythonRegex(r"a\w")158 self.assertTrue(regex.accepts(["a", "0"]))159 self.assertTrue(regex.accepts(["a", "_"]))160 self.assertTrue(regex.accepts(["a", "A"]))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run gabbi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful