import unittest
from kmap.library.orbitaldata import OrbitalData
from kmap import __directory__


class TestOrbitalData(unittest.TestCase):

    def test_default_initialization(self):

        name = 'Test'
        ID = 1
        meta_data = {'origin': 'selfmade'}
        with open(__directory__ +
                  '/../example/data/5A_MO_73.cube', 'r') as f:
            file = f.read()

        data = OrbitalData(file, ID, name=name,
                           meta_data=meta_data)

        self.assertEqual(data.name, name)
        self.assertEqual(data.ID, ID)
        self.assertEqual(data.meta_data, meta_data)

    def test_file_initialization(self):

        ID = 1
        data = OrbitalData.init_from_file(__directory__ +
                                          '/../example/data/' +
                                          '5A_MO_73.cube', ID)

        self.assertEqual(data.name, '5A_MO_73')
        self.assertEqual(data.ID, ID)
        self.assertEqual(data.meta_data, {
                         'origin': 'Cube file generated by NWChem',
                         'alias': 'pentacene_MO_73'})

    def test_online_initialization(self):

        ID = 1
        data = OrbitalData.init_from_online('http://143.50.77.12/' +
                                            'OrganicMolecule/B3LYP/5A/' +
                                            'charge0mult1/5A_MO_73', ID)

        self.assertEqual(data.name, '5A_MO_73')
        self.assertEqual(data.ID, ID)
        self.assertEqual(data.meta_data, {
                         'origin': 'Cube file generated by NWChem',
                         'alias': 'pentacene_MO_73'})
