예제 #1
0
파일: related.py 프로젝트: yvasilev/resql
    def store_location (self, instance):
        if instance.entity_has_foreign_key:
            pk = instance.entity_pk_value
            entity = instance.entity_foreign_key_entity
            instance = tesql.orm.Session.default.get(entity, pk)
            return self.store_location(instance)

        location = self.make_location(instance)

        fileobj = open(location, 'w')

        write_object(instance.entity_as_dictionary, fileobj)
        tesql.orm.Session.default.modify(instance, changed=False)

        for entity in tesql.orm.Entity.entities.itervalues():
            if entity.entity_has_foreign_key:
                fk = entity
                while fk.entity_has_foreign_key:
                    fk = fk.entity_foreign_key_entity
                if fk == type(instance):
                    if tesql.orm.Session.default.has(entity,
                                                     instance.entity_pk_value):
                        inst = tesql.orm.Session.default.get(entity,
                                                             instance.entity_pk_value)

                        write_object(inst.entity_as_dictionary, fileobj)
                        tesql.orm.Session.default.modify(inst, changed=False)
        fileobj.close()
예제 #2
0
    def test_read_object_simple (self):
        obj = make_object('Key1', 'Simple Text')
        write_object(obj, self.fileobj)
        self.fileobj.seek(0)

        nobj = read_object(self.fileobj)

        self.assertEqual(obj, nobj)
예제 #3
0
    def test_read_object_key_empty (self):
        obj = make_object('Section', {})
        write_object(obj, self.fileobj)
        self.fileobj.seek(0)

        nobj = read_object(self.fileobj)

        self.assertEqual(obj, nobj)
예제 #4
0
    def test_read_object_empty_empty (self):
        obj = make_object('', {})
        write_object(obj, self.fileobj)
        self.fileobj.seek(0)

        nobj = read_object(self.fileobj, as_dictionary=True)

        self.assertEqual(obj, nobj)
예제 #5
0
    def test_read_empty_empty (self):
        obj = make_object('', {})
        write_object(obj, self.fileobj)
        self.fileobj.seek(0)

        nobj = DictionaryObject().read(self.fileobj)

        self.assertEqual(obj, nobj)
예제 #6
0
파일: objects.py 프로젝트: yvasilev/resql
    def write(self, dictionary, fileobj, prefix=""):
        if dictionary.name:
            fileobj.write("\n[%s]\n" % (prefix + dictionary.name))

        fileobj.write("\n")

        for obj in dictionary.itervalues():
            write_object(obj, fileobj, prefix=(prefix + dictionary.name + "."))
예제 #7
0
    def test_read_object_multiline_empty (self):
        obj = make_object('Key3', 'MultiLine\n\nw/ empty line')
        write_object(obj, self.fileobj)
        self.fileobj.seek(0)

        nobj = read_object(self.fileobj)

        self.assertEqual(obj, nobj)
예제 #8
0
    def test_read_object_multiline (self):
        obj = make_object('Key2', 'MultiLine text\nSecondLine')
        write_object(obj, self.fileobj)
        self.fileobj.seek(0)

        nobj = read_object(self.fileobj)

        self.assertEqual(obj, nobj)
예제 #9
0
    def test_write_object_empty_strings_simple (self):
        obj = make_object('', {})
        obj.append('Key1', 'Value1')
        obj.append('Key2', 'Value2')
        obj.append('Key3', 'Value3')
        write_object(obj, self.fileobj)

        self.assertEqual(self.fileobj.getvalue(),
            '\nKey1: Value1\nKey2: Value2\nKey3: Value3\n')
예제 #10
0
    def test_read_object_empty_strings_simple (self):
        obj = make_object('', {})
        obj.append('Key1', 'Value1')
        obj.append('Key2', 'Value2')
        obj.append('Key3', 'Value3')
        write_object(obj, self.fileobj)
        self.fileobj.seek(0)

        nobj = read_object(self.fileobj, as_dictionary=True)

        self.assertEqual(obj, nobj)
예제 #11
0
    def test_read_key_strings_simple (self):
        obj = make_object('Section', {})
        obj.append('Key1', 'Value1')
        obj.append('Key2', 'Value2')
        obj.append('Key3', 'Value3')
        write_object(obj, self.fileobj)
        self.fileobj.seek(0)

        nobj = DictionaryObject().read(self.fileobj)

        self.assertEqual(obj, nobj)
예제 #12
0
    def store_location (self, instance):
        location = self.make_location(instance)

        fileobj = open(location, 'w')
        write_object(instance.entity_as_dictionary, fileobj)
        fileobj.close()
예제 #13
0
    def test_write_object_empty_empty (self):
        obj = make_object('', {})
        write_object(obj, self.fileobj)

        self.assertEqual(self.fileobj.getvalue(), '\n')
예제 #14
0
    def test_write_object_key_empty (self):
        obj = make_object('Section', {})
        write_object(obj, self.fileobj)

        self.assertEqual(self.fileobj.getvalue(), '\n[Section]\n\n')
예제 #15
0
    def test_write_object_multiline (self):
        obj = make_object('Key2', 'MultiLine text\nSecondLine')
        write_object(obj, self.fileobj)

        self.assertEqual(self.fileobj.getvalue(),
                         'Key2: MultiLine text\n SecondLine\n')
예제 #16
0
    def test_write_object_multiline_empty (self):
        obj = make_object('Key3', 'MultiLine\n\nw/ empty line')
        write_object(obj, self.fileobj)

        self.assertEqual(self.fileobj.getvalue(),
                         'Key3: MultiLine\n .\n w/ empty line\n')
예제 #17
0
    def test_write_object_simple (self):
        obj = make_object('Key1', 'Simple Text')
        write_object(obj, self.fileobj)

        self.assertEqual(self.fileobj.getvalue(), 'Key1: Simple Text\n')