MCPcopy Index your code
hub / github.com/pytorch/pytorch / testAddFieldByNestedName

Method testAddFieldByNestedName

caffe2/python/schema_test.py:344–390  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

342 self.assertTrue(isinstance(bcd, schema.Scalar))
343
344 def testAddFieldByNestedName(self):
345 f_a = schema.Scalar(blob=core.BlobReference('blob1'))
346 f_b = schema.Struct(
347 ('c', schema.Struct(
348 ('d', schema.Scalar(blob=core.BlobReference('blob2'))),
349 )),
350 )
351 f_x = schema.Struct(
352 ('x', schema.Scalar(blob=core.BlobReference('blob3'))),
353 )
354
355 with self.assertRaises(TypeError):
356 st = schema.Struct(
357 ('a', f_a),
358 ('b', f_b),
359 ('b:c:d', f_x),
360 )
361 with self.assertRaises(TypeError):
362 st = schema.Struct(
363 ('a', f_a),
364 ('b', f_b),
365 ('b:c:d:e', f_x),
366 )
367
368 st = schema.Struct(
369 ('a', f_a),
370 ('b', f_b),
371 ('e:f', f_x),
372 )
373 self.assertEqual(['a', 'b:c:d', 'e:f:x'], st.field_names())
374 self.assertEqual(['blob1', 'blob2', 'blob3'], st.field_blobs())
375
376 st = schema.Struct(
377 ('a', f_a),
378 ('b:c:e', f_x),
379 ('b', f_b),
380 )
381 self.assertEqual(['a', 'b:c:e:x', 'b:c:d'], st.field_names())
382 self.assertEqual(['blob1', 'blob3', 'blob2'], st.field_blobs())
383
384 st = schema.Struct(
385 ('a:a1', f_a),
386 ('b:b1', f_b),
387 ('a', f_x),
388 )
389 self.assertEqual(['a:a1', 'a:x', 'b:b1:c:d'], st.field_names())
390 self.assertEqual(['blob1', 'blob3', 'blob2'], st.field_blobs())
391
392 def testContains(self):
393 st = schema.Struct(

Callers

nothing calls this directly

Calls 4

field_namesMethod · 0.95
field_blobsMethod · 0.95
assertRaisesMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected