Beispiel #1
0
    def test_save_and_load(self, tmp_path):
        path = tmp_path / "doc.json"
        doc = FileMappedDocument(path)

        doc["number"] = 42
        doc["nested"] = {"foo": "bar"}

        doc.save()

        doc = FileMappedDocument(path)
        doc.load()

        assert doc == {"number": 42, "nested": {"foo": "bar"}}
Beispiel #2
0
    def test_load_merges_content(self, tmp_path):
        path = tmp_path / "doc.json"
        # save state
        doc = FileMappedDocument(path)
        doc["number"] = 42
        doc["nested"] = {"foo": "bar"}
        doc.save()

        # save state from elsewhere
        doc1 = FileMappedDocument(path)
        doc1["another"] = 420
        doc1["nested"]["baz"] = "ed"
        doc1.save()

        # load state
        doc.load()
        assert doc == {"number": 42, "another": 420, "nested": {"foo": "bar", "baz": "ed"}}