#! /usr/bin/env python
# -*- coding: iso-8859-1 -*-
#-----------------------------------------------------------------------------
# Modeling Framework: an Object-Relational Bridge for python
#
# Copyright (c) 2001-2004 Sbastien Bigaret <sbigaret@users.sourceforge.net>
# All rights reserved.
#
# This file is part of the Modeling Framework.
#
# This code is distributed under a "3-clause BSD"-style license;
# see the LICENSE file for details.
#-----------------------------------------------------------------------------
"""Test the Model"""
import unittest
if __name__ == "__main__":
import utils, sys
utils.fixpath()
from Modeling import Model
class TestModuleFunctions(unittest.TestCase):
"Tests for module Model"
def checkStoreEmployee(self, model):
"Minimum checking of model StoreEmployees"
entities=('Store','Employee','Executive','SalesClerk','Mark','Address','Holidays')
self.assertEqual(len(model.entities()), len(entities))
for e in entities:
self.failIf(e not in model.entitiesNames(), "%s not in model"%e)
def test_01_loadModel(self):
"[module Model] loadModel"
from Modeling.ModelSet import defaultModelSet
self.assertRaises(ImportError, Model.loadModel,
'testPackages/StoreEmployees/does_not_exists.py')
self.assertRaises(IOError, Model.loadModel,
'testPackages/StoreEmployees/does_not_exists.xml')
self.assertRaises(ValueError, Model.loadModel,
'testPackages/StoreEmployees/Mark.py')
# PyModel
model=Model.loadModel('testPackages/StoreEmployees/pymodel_StoreEmployees.py')
self.failUnless(model)
self.failIf(model in defaultModelSet().models())
self.checkStoreEmployee(model)
# xml-model in .py
model=Model.loadModel('testPackages/StoreEmployees/model_StoreEmployees.py')
self.failUnless(model)
self.failIf(model in defaultModelSet().models())
self.checkStoreEmployee(model)
# xml-model in .xml
model=Model.loadModel('testPackages/StoreEmployees/model_StoreEmployees.xml')
self.failUnless(model)
self.failIf(model in defaultModelSet().models())
self.checkStoreEmployee(model)
class TestModel(unittest.TestCase):
"Tests for class Model. Empty for now"
def test_truc(self):
"[Model] Tests that 1 is equal to 1"
self.assertEqual(1, 1)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestModuleFunctions, "test_"))
suite.addTest(unittest.makeSuite(TestModel, "test_"))
return suite
if __name__ == "__main__":
errs = utils.run_suite(test_suite())
sys.exit(errs and 1 or 0)
|