Beispiel #1
0
    def test_fileops_modellib(self):
        # check file operations of modellib
        
        fpath = os.path.join('..', 'sitforc')
        os.rename(os.path.join(fpath, 'modellib.sfm'),
                  os.path.join(fpath, 'modellib2.sfm'))
        try:
            with catch_warnings(record=True) as w:
                modellib.reset()
                self.assertEqual(len(w), 1)
                self.assertTrue(issubclass(w[0].category, SitforcWarning)) 
                
            with open(os.path.join(fpath, 'modellib.sfm'), 'w') as fobj:
                fobj.write('[section\nwithout=end')
            try:
                self.assertRaises(configobj.ConfigObjError, modellib.reset)
            finally:
                os.remove(os.path.join(fpath, 'modellib.sfm'))
            
            try:    
                modellib.new_model('m1', None, '2 + 3', None, c=2)
                modellib.save()
                modelfile='''[m1]
func = 2 + 3
c = 2
'''
                with open(os.path.join(fpath, 'modellib.sfm')) as fobj:
                    self.assertEqual(modelfile, fobj.read())
            finally:
                os.remove(os.path.join(fpath, 'modellib.sfm'))
            
                      
        finally:
            os.rename(os.path.join(fpath, 'modellib2.sfm'),
                      os.path.join(fpath, 'modellib.sfm'))
Beispiel #2
0
 def tearDown(self):
     modellib.reset()