예제 #1
0
def test_multi_metadata():
    '''Tests generate year template by comparing to known good result'''
    multi_sim = SolveTemplate(cfgfile='tests/testConfig.cfg')
    meta = multi_sim.generate_metadata()
    with open('tests/metadata.json', 'r') as test_meta:
        metad = json.load(test_meta)
    assert json.dumps(meta, indent=2) == json.dumps(metad, indent=2)
예제 #2
0
파일: test_multi.py 프로젝트: jebob/openCEM
def test_multi_metadata():
    '''Tests generate year template by comparing to known good result'''
    X = SolveTemplate(cfgfile='tests/Sample.cfg')
    meta = X.generate_metadata()
    with open('tests/metadata.json', 'r') as f:
        metad = json.load(f)
    assert json.dumps(meta, indent=2) == json.dumps(metad, indent=2)
예제 #3
0
파일: test_multi.py 프로젝트: jebob/openCEM
def test_multi_template_second():
    '''Tests generate second (and later) year template by comparing to known good result'''
    X = SolveTemplate(cfgfile='tests/Sample.cfg')
    X.generateyeartemplate(X.Years[1], test=True)
    with open(X.tmpdir + 'Sim2025.dat') as ff:
        fromfile = ff.readlines()
    with open('tests/Sim2025.dat') as tf:
        tofile = tf.readlines()
    # Check that they are mostly the same, but for tempdir entries
    d = SequenceMatcher(None, fromfile, tofile)
    assert d.ratio() >= 0.99657534
예제 #4
0
def test_multi_template_first():
    '''Tests generate first year template by comparing to known good result'''
    multi_sim = SolveTemplate(cfgfile='tests/testConfig.cfg')
    multi_sim.generateyeartemplate(multi_sim.Years[0], test=True)
    testfile = str(multi_sim.wrkdir) + '/Sim2020.dat'
    text1 = open(testfile).readlines()
    text2 = open('tests/Sim2020.dat').readlines()
    if filecmp.cmp(testfile, 'tests/Sim2020.dat', shallow=False):
        assert True
    s = SequenceMatcher(None, text1, text2)
    print(s.ratio())
    assert s.ratio() > 0.999
예제 #5
0
def test_multi_template_second(delete_sim2025_dat):
    '''Tests generate second (and later) year template by comparing to known good result'''
    multi_sim = SolveTemplate(cfgfile='tests/testConfig.cfg', wrkdir=Path(''))
    multi_sim.generateyeartemplate(multi_sim.Years[1], test=True)
    testfile = str(multi_sim.wrkdir) + '/Sim2025.dat'
    text1 = open(testfile).readlines()
    text2 = open('tests/Sim2025.dat').readlines()
    if filecmp.cmp(
            str(multi_sim.wrkdir) + '/Sim2025.dat', 'tests/Sim2025.dat'):
        assert True
    s = SequenceMatcher(None, text1, text2)
    assert s.ratio() > 0.999
예제 #6
0
파일: test_multi.py 프로젝트: jebob/openCEM
def test_multi_bad_file(option, value):
    ''' Assert validate bad config option'''
    fp = tempfile.NamedTemporaryFile()
    with open('tests/Sample.cfg') as fin:
        with open(fp.name, 'w') as fo:
            for line in fin:
                if option in line:
                    line = value + '\n'
                fo.write(line)
    with pytest.raises(OSError):
        SolveTemplate(cfgfile=fp.name)
예제 #7
0
def test_multi_bad_file(option, value):
    ''' Assert that multi detects missing files in config'''
    with open('tests/testConfig.cfg') as sample:
        with tempfile.NamedTemporaryFile(mode='w', dir='tests') as temp_sample:
            for line in sample:
                if option in line:
                    line = value + '\n'
                temp_sample.write(line)
                temp_sample.flush()
            with pytest.raises(OSError):
                SolveTemplate(cfgfile=temp_sample.name)
예제 #8
0
def test_multi_bad_cfg(option, value):
    ''' Assert validate bad config option by replacing known bad options in sample file'''
    with open('tests/testConfig.cfg') as sample:
        with tempfile.NamedTemporaryFile(mode='w', dir='tests') as temp_sample:
            for line in sample:
                if option in line:
                    line = value + '\n'
                temp_sample.write(line)
                temp_sample.flush()
            with pytest.raises(ValueError):
                SolveTemplate(cfgfile=temp_sample.name)
예제 #9
0
파일: msolve.py 프로젝트: bje-/openCEM
    action='store_true')

parser.add_argument(
    "-k",
    "--keepfiles",
    help="Save generated files onto a folder with the same name as the configuration file",
    action='store_true')

# parse arguments into args structure
args = parser.parse_args()

# Read configuration file name from
cfgfile = args.config

# create Multi year simulation
X = SolveTemplate(cfgfile, solver=args.solver, log=args.log)

# make a temporary directoy
if args.keepfiles:
    path = cfgfile.split(".")[0] + '/'
    if not os.path.exists(path):
        os.mkdir(path)
    X.tmpdir = path

# instruct the solver to launch the multi year simulation
print("openCEM msolve.py: Runtime %s (pre solver)" % str(
    datetime.timedelta(seconds=(time.time() - start_time))))
X.solve()
print("openCEM msolve.py: Runtime %s (post solver)" % str(
    datetime.timedelta(seconds=(time.time() - start_time))))
예제 #10
0
    "--templatetest",
    help=
    "Testing mode where only short dispatch periods are use. Warning, it disables clustering",
    action="store_true",
)

# parse arguments into args structure
args = parser.parse_args()

# Read configuration file name from
cfgfile = args.config

SIM_DIR = cfgfile.split(".")[0] + "/"
if not os.path.exists(SIM_DIR):
    os.mkdir(SIM_DIR)

# create Multi year simulation
X = SolveTemplate(cfgfile,
                  solver=args.solver,
                  log=args.log,
                  tmpdir=SIM_DIR,
                  resume=args.resume,
                  templatetest=args.templatetest)

# instruct the solver to launch the multi year simulation
print("openCEM msolve.py: Runtime %s (pre solver)" %
      str(datetime.timedelta(seconds=(time.time() - start_time))))
X.solve()
print("openCEM msolve.py: Runtime %s (post solver)" %
      str(datetime.timedelta(seconds=(time.time() - start_time))))
예제 #11
0
파일: test_multi.py 프로젝트: jebob/openCEM
def test_multi_template_first():
    '''Tests generate first year template by comparing to known good result'''
    X = SolveTemplate(cfgfile='tests/Sample.cfg')
    X.generateyeartemplate(X.Years[0], test=True)
    assert filecmp.cmp(X.tmpdir + 'Sim2020.dat', 'tests/Sim2020.dat')
예제 #12
0
파일: test_multi.py 프로젝트: jebob/openCEM
def test_multi_conf_file_not_found():
    ''' Fail if file does not exist'''
    with pytest.raises(FileNotFoundError):
        SolveTemplate(cfgfile='Nofile.cfg')
예제 #13
0
def test_multi_get_model_options(year, value):
    '''Test that model options are generated for each year'''
    multi_sim = SolveTemplate(cfgfile='tests/testConfig.cfg')
    options = multi_sim.get_model_options(year)
    assert options.build_intercon_manual == value