# coding: utf-8

from __future__ import unicode_literals, division

"""
Created on Jun 1, 2012
"""


__author__ = "Shyue Ping Ong, Stephen Dacek"
__copyright__ = "Copyright 2012, The Materials Project"
__version__ = "0.1"
__maintainer__ = "Shyue Ping Ong"
__email__ = "shyue@mit.edu"
__date__ = "Jun 1, 2012"

import unittest
import os
import glob
import shutil
import datetime

from custodian.vasp.handlers import VaspErrorHandler, \
    UnconvergedErrorHandler, MeshSymmetryErrorHandler, WalltimeHandler, \
    MaxForceErrorHandler, PositiveEnergyErrorHandler, PotimErrorHandler, \
    FrozenJobErrorHandler, AliasingErrorHandler, StdErrHandler
from pymatgen.io.vasp import Incar, Poscar, Structure, Kpoints, VaspInput


test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..",
                        'test_files')

cwd = os.getcwd()


def clean_dir():
    for f in glob.glob("error.*.tar.gz"):
        os.remove(f)
    for f in glob.glob("custodian.chk.*.tar.gz"):
        os.remove(f)


class VaspErrorHandlerTest(unittest.TestCase):

    def setUp(self):
        if "VASP_PSP_DIR" not in os.environ:
            os.environ["VASP_PSP_DIR"] = test_dir
        os.chdir(test_dir)
        shutil.copy("INCAR", "INCAR.orig")
        shutil.copy("KPOINTS", "KPOINTS.orig")
        shutil.copy("POSCAR", "POSCAR.orig")
        shutil.copy("CHGCAR", "CHGCAR.orig")

    def test_frozen_job(self):