import pytest, netCDF4, os
from dqc_wrapper.test00_file_format import FileFormat, return_extension
from dqc_wrapper.checker import create_parser
import dqc_wrapper.utils.grib_content as gcont
import gc

@pytest.fixture()
def ncfile(pytestconfig):
    return pytestconfig.getoption("ncfile")

@pytest.fixture()
def gribfile(pytestconfig):
    return pytestconfig.getoption("gribfile")


def initialize(file_path):
    args = create_parser(['--test', 'file_format', '--input',
                          file_path])
    return FileFormat(args)

""" UNIT TESTS """

def test_return_extension():
    return_extension("fake.grib")
    with pytest.raises(Exception):
        # Notice this is unhandled
        return_extension("not_dataset.jpg")

""" INTEGRATION TESTS """
def test_main_nc(ncfile):
    test = initialize(ncfile)
    test.main()


def test_main_grib(gribfile):
    test = initialize(gribfile)
    test.main()

def test_main_error():
    with pytest.raises(Exception):
        test = initialize("fake_path")
        test.main()



