MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / check_encode_then_decode

Method check_encode_then_decode

test/test_bson.py:137–176  ·  view source on GitHub ↗
(self, doc_class=dict, decoder=decode, encoder=encode)

Source from the content-addressed store, hash-verified

135 self.assertRaises(InvalidBSON, decode, data)
136
137 def check_encode_then_decode(self, doc_class=dict, decoder=decode, encoder=encode):
138 def helper(doc):
139 self.assertEqual(doc, (decoder(encoder(doc_class(doc)))))
140 self.assertEqual(doc, decoder(encoder(doc)))
141
142 helper({})
143 helper({"test": "hello"})
144 self.assertIsInstance(decoder(encoder({"hello": "world"}))["hello"], str)
145 helper({"mike": -10120})
146 helper({"long": Int64(10)})
147 helper({"really big long": 2147483648})
148 helper({"hello": 0.0013109})
149 helper({"something": True})
150 helper({"false": False})
151 helper({"an array": [1, True, 3.8, "world"]})
152 helper({"an object": doc_class({"test": "something"})})
153 helper({"a binary": Binary(b"test", 100)})
154 helper({"a binary": Binary(b"test", 128)})
155 helper({"a binary": Binary(b"test", 254)})
156 helper({"another binary": Binary(b"test", 2)})
157 helper({"binary packed bit vector": Binary(b"\x10\x00\x7f\x07", 9)})
158 helper({"binary int8 vector": Binary(b"\x03\x00\x7f\x07", 9)})
159 helper({"binary float32 vector": Binary(b"'\x00\x00\x00\xfeB\x00\x00\xe0@", 9)})
160 helper(SON([("test dst", datetime.datetime(1993, 4, 4, 2))]))
161 helper(SON([("test negative dst", datetime.datetime(1, 1, 1, 1, 1, 1))]))
162 helper({"big float": float(10000000000)})
163 helper({"ref": DBRef("coll", 5)})
164 helper({"ref": DBRef("coll", 5, foo="bar", bar=4)})
165 helper({"ref": DBRef("coll", 5, "foo")})
166 helper({"ref": DBRef("coll", 5, "foo", foo="bar")})
167 helper({"ref": Timestamp(1, 2)})
168 helper({"foo": MinKey()})
169 helper({"foo": MaxKey()})
170 helper({"$field": Code("function(){ return true; }")})
171 helper({"$field": Code("return function(){ return x; }", scope={"x": False})})
172
173 def encode_then_decode(doc):
174 return doc_class(doc) == decoder(encode(doc), CodecOptions(document_class=doc_class))
175
176 qcheck.check_unittest(self, encode_then_decode, qcheck.gen_mongo_dict(3))
177
178 def test_encode_then_decode(self):
179 self.check_encode_then_decode()

Calls 8

Int64Class · 0.90
BinaryClass · 0.90
SONClass · 0.90
DBRefClass · 0.90
TimestampClass · 0.90
MinKeyClass · 0.90
MaxKeyClass · 0.90
CodeClass · 0.90

Tested by

no test coverage detected