"""
Tests for the UCD explaining hack.
"""

import os
os.environ["GAVO_OOTTEST"] = "dontcare"

from gavo import api

RESDIR = "ucds"

from gavo.helpers import testhelpers

ucdexplainer, _ = api.loadPythonModule(os.path.join(
		api.getConfig("inputsDir"), RESDIR, "res", "ucdexplainer"))


class _UCDExplainingTest(testhelpers.VerboseTest,
		metaclass=testhelpers.SamplesBasedAutoTest):
	def _runTest(self, sample):
		ucd, expected = sample
		found = ucdexplainer.explain(ucd)
		self.assertEqual(expected, found)


class AtomTest(_UCDExplainingTest):
	samples = [
		("em.freq.cutoff", "Cutoff frequency"),
		("phys.veloc", "Space velocity"),
	]


class MiscMetaTest(_UCDExplainingTest):
	samples = [
		("meta.note;phys.absorption", "Note or remark (longer than a code or flag) on extinction or absorption along the line of sight"),
		("meta.code;src", "Code or flag describing an observed source viewed on the sky"),
		("meta.ref.ivoid;meta.curation", "Identifier as recommended  in the ivoa  (dereferenceable) for an identity of man/organization responsible for the data"),
	]


class OfAMetaTest(_UCDExplainingTest):
	samples = [
		("meta.id.assoc;src.sample", "Identifier of associated counterpart of a sample"),
		("meta.id;meta.table", "Identifier, name or designation of a table or catalogue"),
	]


class InATest(_UCDExplainingTest):
	samples = [
		("instr.background;em.radio", "Instrumental background in the radio part of the spectrum"),
	]


class ColourTest(_UCDExplainingTest):
	samples = [
		("phot.color; em.opt.B; em.opt.V", "Color index or magnitude difference between the optical band between 400 and 500 nm and the optical band between 500 and 600 nm"),
		("phot.color; em.line.HI; em.radio.20MHz", "Color index or magnitude difference between the 21cm hydrogen line and the radio below 20 MHz"),
	]


if __name__=="__main__":
	testhelpers.main(AtomTest)
