from dqc_wrapper.test01_standard_compliance import StandardComplianceTest
from dqc_wrapper.unit_tests.conftest import dirs

def test_runcfchecker():
    test = StandardComplianceTest([dirs.nc_file], dirs.test_dir, '', 'tas')
    res = test.run_cfchecker(dirs.nc_file)
    assert 'cfchecks' in res.decode('UTF-8')


def test_netcdf_test():
    test = StandardComplianceTest([dirs.nc_file], dirs.test_dir, '', 'tas')
    res = test.netcdf_test(dirs.nc_file)
    assert 'ok' in res


def test_grib_test():
    test = StandardComplianceTest([dirs.grib_cds], dirs.test_dir, '', 'tas')
    res = test.grib_test(dirs.grib_cds, {'171129': {'grib_codes': {'GRIBEditionNumber': '2'}}})
    assert 'ok' in res
    test = StandardComplianceTest([dirs.grib_cds], dirs.test_dir, '', 'tas')
    res = test.grib_test(dirs.grib_cds, {
        '171129': {'grib_codes': {'GRIBEditionNumber': '45'}}})
    assert 'err' in res


def test_main():
    test = StandardComplianceTest([dirs.nc_file], dirs.test_dir, '', 'tas')
    res = test.main()
    assert 'ok' in res.values()
    test = StandardComplianceTest([dirs.grib_cds], dirs.test_dir, '', 'tas')
    res = test.main()
    assert 'err' in res.values()

test_runcfchecker()