import ast
import sys
import csv
import datetime
import os
import unittest
import subprocess
import pandas as pd
import numpy as np
import h5py
from pymongo import MongoClient
from fluxpy import __path__ as fluxpy_module_path
from fluxpy import DB
from fluxpy.models import KrigedXCO2Matrix, SpatioTemporalMatrix, XCO2Matrix
from fluxpy.mediators import Grid3DMediator, Grid4DMediator, Unstructured3DMediator, DB

FNULL = open(os.devnull, 'w')

class TestManage(unittest.TestCase):
    '''Tests manage.py command line functionality'''

    db = MongoClient()[DB]

    def load_test_data(self):
        # remove any stale sample data and reload
        cmd = 'python ../../manage.py remove -n casa_gfed_load_test'
        subprocess.call(cmd, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)

        cmd = '''python ../../manage.py load -p casagfed2004.mat -n casa_gfed_load_test -m SpatioTemporalMatrix'''
        subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)

    def test_load_command(self):
        '''