source: trunk/test/sucasa/models/test_amplbook2.py @ 1768

Last change on this file since 1768 was 1768, checked in by wehart, 11 years ago

Rework of Coopr to use the new PyUtilib? package decomposition.

NOTE: to use Coopr with this update, we need to work with a new version of coopr_install.

File size: 1.3 KB
Line 
1#
2# Unit Tests for complete examples
3#
4
5import unittest
6import os
7import sys
8from os.path import abspath, dirname
9topdir = dirname(dirname(abspath(__file__)))+os.sep+".."+os.sep+".."
10sys.path.insert(0, topdir)
11currdir = dirname(abspath(__file__))+os.sep
12
13from coopr.sucasa import parse_mapfile,MILPSymbInfo,parse_ampl
14import pyutilib.misc
15import pyutilib.th
16import glob
17
18#
19# Test class
20#
21class TestAmplbook2(pyutilib.th.TestCase): pass
22#
23# The directory with the test data
24#
25data_dir=topdir+os.sep+"example"+os.sep+"pyomo"+os.sep+"amplbook2"+os.sep
26#
27# Function used to generate a *.map output file, which is compared against a baseline
28#
29def create_map(name):
30    prefix=data_dir+name
31    pyutilib.misc.setup_redirect(prefix+".out")
32    ans = parse_ampl(filename=data_dir+name+".mod")
33    sinfo = MILPSymbInfo()
34    ans.exported_symbols.add("*")
35    ans.initialize(sinfo,quiet=True)
36    sinfo.write_mapfile(prefix+".out.map")
37    pyutilib.misc.reset_redirect()
38    return [prefix+".out.map",[prefix+".out"]]
39#
40# Iterate over all files to populate the test class
41#
42files = glob.glob(data_dir+"*.mod")
43for file in files:
44    bname=os.path.basename(file)
45    name=bname.split('.')[0]
46    TestAmplbook2.add_baseline_test(fn=create_map, baseline=data_dir+name+".map", name=name)
47
48#
49# Execute tests when run from the command line
50#
51if __name__ == "__main__":
52   unittest.main()
Note: See TracBrowser for help on using the repository browser.