#!/usr/bin/env python
from coral import loadModel,saveModel,isSameModel

import os

file = "carpark.xml"

m_ref = loadModel(file)

for i in range(10):
    m = loadModel(file)
    print
    print
    print "Checking, pass",i+1, "(", file, ")"
    print
    assert(isSameModel(m_ref, m))
    saveModel("tmp/out" + str(i) + "_LoadSaveModels.xml", m)
    print "re-loading"
    os.rename("tmp/out" + str(i) + "_LoadSaveModels.xml",
              "tmp/out" + str(i) + "_2_LoadSaveModels.xml")
    m = loadModel("tmp/out" + str(i) + "_2_LoadSaveModels.xml")
    print "Loaded" ,m, m.__XMIid__()
    assert(m)
    assert(isSameModel(m_ref, m))
