#!/usr/bin/env python

from __future__ import print_function

import unittest
import os
import shlex
import subprocess as sp

class TestExpWeb(unittest.TestCase):

    def run_expweb_on_experiment(self, archive, model, expt_name):

        test_dir = os.path.dirname(os.path.realpath(__file__))
        exe = os.path.join(os.path.join(test_dir, '../'), 'expweb.py')
        web_path = os.path.join(test_dir, 'outputs/payu-experiments',
                                model, expt_name, 'web')

        cmd = '{} {} {} '.format(exe, archive, web_path)

        print('Executing: {}'.format(cmd))
        ret = sp.call(shlex.split(cmd))
        assert(ret == 0)

        # Check that some files exist. 

    def test_access_om_1440x1080(self):
        """
        Test creating experiment web page and plots for access_om_1440x1080.
        """

        archive = '/short/v45/nah599/access/archive/access-om_1440x1080/'
        model = 'access'
        expt_name = 'access-om_1440x1080'

        self.run_expweb_on_experiment(archive, model, expt_name)

    def test_access_cm_1440x1080_0p2_0(self):
        """
        Test creating experiment web page and plots for access-cm_1440x1080-0.2_0

        Copy this method to run the same test for a different experiment.
        """

        archive = '/short/v45/nah599/access/archive/access-cm_1440x1080-0.2_0'
        model = 'access'
        expt_name = 'access-cm_1440x1080-0.2_0'

        self.run_expweb_on_experiment(archive, model, expt_name)

    def test_access_cm_1440x1080_0p2_1(self):
        """
        Test creating experiment web page and plots for access-cm_1440x1080-0.2_1

        Copy this method to run the same test for a different experiment.
        """

        archive = '/short/v45/nah599/access/archive/access-cm_1440x1080-0.2_1'
        model = 'access'
        expt_name = 'access-cm_1440x1080-0.2_1'

        self.run_expweb_on_experiment(archive, model, expt_name)

    def test_access_cm_1440x1080_0p2_2(self):
        """
        Test creating experiment web page and plots for access-cm_1440x1080-0.2_2

        Copy this method to run the same test for a different experiment.
        """

        archive = '/short/v45/nah599/access/archive/access-cm_1440x1080-0.2_2'
        model = 'access'
        expt_name = 'access-cm_1440x1080-0.2_2'

        self.run_expweb_on_experiment(archive, model, expt_name)


if __name__ == '__main__':
    unittest.main()
