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

Method test_set_after_close

test/test_grid_file.py:679–722  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

677 self.assertEqual("aé".encode("iso-8859-1"), g.read())
678
679 def test_set_after_close(self):
680 f = GridIn(self.db.fs, _id="foo", bar="baz")
681
682 self.assertEqual("foo", f._id)
683 self.assertEqual("baz", f.bar)
684 self.assertRaises(AttributeError, getattr, f, "baz")
685 self.assertRaises(AttributeError, getattr, f, "uploadDate")
686
687 self.assertRaises(AttributeError, setattr, f, "_id", 5)
688 if _IS_SYNC:
689 f.bar = "foo"
690 f.baz = 5
691 else:
692 f.set("bar", "foo")
693 f.set("baz", 5)
694
695 self.assertEqual("foo", f._id)
696 self.assertEqual("foo", f.bar)
697 self.assertEqual(5, f.baz)
698 self.assertRaises(AttributeError, getattr, f, "uploadDate")
699
700 f.close()
701
702 self.assertEqual("foo", f._id)
703 self.assertEqual("foo", f.bar)
704 self.assertEqual(5, f.baz)
705 self.assertTrue(f.uploadDate)
706
707 self.assertRaises(AttributeError, setattr, f, "_id", 5)
708 if _IS_SYNC:
709 f.bar = "a"
710 f.baz = "b"
711 else:
712 f.set("bar", "a")
713 f.set("baz", "b")
714 self.assertRaises(AttributeError, setattr, f, "upload_date", 5)
715
716 g = GridOut(self.db.fs, f._id)
717 if not _IS_SYNC:
718 g.open()
719 self.assertEqual("a", g.bar)
720 self.assertEqual("b", g.baz)
721 # Versions 2.0.1 and older saved a _closed field for some reason.
722 self.assertRaises(AttributeError, getattr, g, "_closed")
723
724 def test_context_manager(self):
725 contents = b"Imagine this is some important data..."

Callers

nothing calls this directly

Calls 5

setMethod · 0.95
closeMethod · 0.95
openMethod · 0.95
GridInClass · 0.90
GridOutClass · 0.90

Tested by

no test coverage detected