#!/usr/bin/env python

import os
import sys
import shutil

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from runtest_dirac import Filter, TestRun

test = TestRun(__file__, sys.argv)

f = Filter()
f.add(from_string = 'Energy at final geometry is',
      num_lines   = 3,
      rel_tolerance   = 1.0e-4)

test.run(['O.inp'], ['O.mol'], args='--outcmo')
if os.path.isfile('CHECKPOINT.h5'):
    ext = '.h5'
elif os.path.isfile('CHECKPOINT.noh5.tar.gz'):
    ext = '.noh5.tar.gz'
shutil.move('CHECKPOINT'+ext, 'O'+ext)
test.run(['H2O.inp'], ['H2O.mol'], f, args='--copy=O.h5')

test.run(['O.2c_iotc.inp'], ['O.mol'],args='--outcmo')
shutil.move('CHECKPOINT'+ext, 'O'+ext)
test.run(['H2O.2c_iotc.inp'], ['H2O.mol'], f, args='--copy="O.h5"')

test.run(['O.2c_iotc_noamfi.inp'], ['O.mol'], args='--outcmo')
shutil.move('CHECKPOINT'+ext, 'O'+ext)
test.run(['H2O.2c_iotc_noamfi.inp'], ['H2O.mol'], f, args='--copy=O.h5')

sys.exit(test.return_code)
