#!/opt/conda/conda-bld/pyciao_1701809863847/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeh/bin/python3
from cxcstdhdr import *
import sys
import io
import os
import unittest
import warnings 

warnings.simplefilter("ignore", Warning)

class TestCXCHeader(unittest.TestCase):
    

    def test_01(self):
        """
        Tests of print __repr__()
            - empty CXCStandardHeader object
            - CXCStandardHeader object containing "ALL" keys
            - CXCStandardHeader object containing ["T_b","O_e","C_p"] keys 
              - also tests case-insensitivity for *_b, *_e, and *_p groupings

        Tests for CXCStandardHeader.build_hdr()
            - invalid input :  <nothing>
            - invalid input :  None
            - invalid input :  ""
            - invalid input :  integer
            - invalid input :  ["valid grouping", "non-existent grouping"]
            - good input    :  comma-separated list of groupings "event,Primary,NonSI"
            - good input    :  string "ALL" 
            - good input    :  list of valid grouping strings ["T_b","O_e","C_p"]
        """

        # create new CXCStandardHeader object
        try:
            hdr = CXCStandardHeader()
        except Exception as ex:
            print(str(ex))
            raise Exception("create empty CXCStandardHeader failed")

        result = str(hdr)
        expected = "This header does not contain any keys.  Use build_hdr() to populate header.\n"
        self.assertIn(result, expected, "print header without keys FAILED")

        try:
            hdr.build_hdr()
        except Exception as ex:
            if "build_hdr() missing 1 required positional argument: 'groupings'" not in str(ex):
                raise Exception("build_hdr() FAILED")

        try:
            hdr.build_hdr(None)
        except Exception as ex:
            if "Please specify header grouping(s)" not in str(ex): 
                raise Exception("build_hdr(None) FAILED")

        try:
            hdr.build_hdr("")
        except Exception as ex:
            if "Please specify header grouping(s)" not in str(ex):
                raise Exception("build_hdr("") FAILED")

        try:
            hdr.build_hdr([])
        except Exception as ex:
            if "Please specify header grouping(s)" not in str(ex):
                raise Exception("build_hdr([]) FAILED")

        try:
            hdr.build_hdr(2)
        except Exception as ex:
            if "Input groupings must be a string or list of strings" not in str(ex):
                raise Exception("build_hdr(2) FAILED")

        try:
            hdr.build_hdr(["Basic ","FOO"])
        except Exception as ex:
            if "'FOO' is not a valid group" not in str(ex):
                raise Exception("build_hdr(['BASIC','FOO']) FAILED")


        try:
            hdr.build_hdr("event, Primary, NonSI")
        except Exception as ex:
            raise Exception("build_hdr('event,Primary,NonSI') FAILED")


        expected = "Name: ASCDSVER   Groupings: ['BASIC', 'EVENT', 'NONSI', 'C_1', 'C_B', 'C_E']\nName: ASPTYPE    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: BTIMCORR   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_B', 'T_E']\nName: BTIMDRFT   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_B', 'T_E']\nName: BTIMNULL   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_B', 'T_E']\nName: BTIMRATE   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_B', 'T_E']\nName: CHECKSUM   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'C_1', 'C_2', 'C_3', 'C_B', 'C_E', 'C_P']\nName: CLOCKAPP   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: CREATOR    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'C_1', 'C_2', 'C_3', 'C_B', 'C_E', 'C_P']\nName: CTI_APP    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: CTI_CORR   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: CYCLE      Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: DATACLAS   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DATAMODE   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DATASUM    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'C_1', 'C_2', 'C_3', 'C_B', 'C_E', 'C_P']\nName: DATE       Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: DATE-END   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: DATE-OBS   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: DEC_NOM    Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: DEC_PNT    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: DEC_TARG   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: DEFOCUS    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: DETNAM     Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DS_IDENT   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'O_1', 'O_3', 'O_B', 'O_E', 'O_P']\nName: DTCOR      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DTH_AVG    Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DY_AVG     Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DZ_AVG     Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: EQUINOX    Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: EXPOSURE   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: FLSHTIME   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_B', 'T_E']\nName: FOC_LEN    Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: FP_TEMP    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: GRATING    Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: HDUCLAS1   Groupings: ['BASIC', 'EVENT', 'NONSI', 'C_1', 'C_2', 'C_B', 'C_E']\nName: HDUCLAS2   Groupings: ['BASIC', 'EVENT', 'NONSI', 'C_1', 'C_2', 'C_B', 'C_E']\nName: HDUCLAS3   Groupings: ['BASIC', 'EVENT', 'NONSI', 'C_1', 'C_2', 'C_B', 'C_E']\nName: HDUCLASS   Groupings: ['BASIC', 'EVENT', 'NONSI', 'C_1', 'C_2', 'C_B', 'C_E']\nName: INSTRUME   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'O_1', 'O_3', 'O_4', 'O_B', 'O_E', 'O_P']\nName: LIVETIME   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: MISSION    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'O_1', 'O_3', 'O_4', 'O_B', 'O_E', 'O_P']\nName: MJDREF     Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: MJD-OBS    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: OBI_NUM    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'O_B', 'O_E', 'O_P']\nName: OBJECT     Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: OBSERVER   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: OBS_ID     Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'O_1', 'O_3', 'O_B', 'O_E', 'O_P']\nName: OBS_MODE   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: ONTIME     Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: ORIGIN     Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'C_1', 'C_2', 'C_3', 'C_B', 'C_E', 'C_P']\nName: RADESYS    Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: RAND_PI    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: RAND_SKY   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: RAND_TG    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: RA_NOM     Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: RA_PNT     Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: RA_TARG    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: READMODE   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: REVISION   Groupings: ['BASIC', 'EVENT', 'NONSI', 'C_1', 'C_B', 'C_E']\nName: ROLL_NOM   Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: ROLL_PNT   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: SEQ_NUM    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'O_1', 'O_3', 'O_B', 'O_E', 'O_P']\nName: SHYMINUS   Groupings: ['EVENT', 'O_E']\nName: SHYPLUS    Groupings: ['EVENT', 'O_E']\nName: SIM_X      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: SIM_Y      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: SIM_Z      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: STARTMJF   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: STARTMNF   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: STARTOBT   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: STOPMJF    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: STOPMNF    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: TASSIGN    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TELESCOP   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'O_1', 'O_3', 'O_4', 'O_B', 'O_E', 'O_P']\nName: TIERABSO   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIERRELA   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIMEDEL    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIMEPIXR   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIMEREF    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIMESYS    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: TIMEUNIT   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: TIMEZERO   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: TIMVERSN   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TITLE      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: TLMVER     Groupings: ['EVENT', 'C_1', 'C_E']\nName: TLM_FMT    Groupings: ['EVENT', 'O_E']\nName: TSTART     Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: TSTOP      Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\n"


        result = str(hdr)
        self.assertIn(result, expected, "print EVENT, PRIMARY, and NONSI keys FAILED")



        try:
            hdr.build_hdr("all")
        except Exception as ex:
            raise Exception("build_hdr(all) FAILED")
 

        expected ="Name: ASCDSVER   Groupings: ['BASIC', 'EVENT', 'NONSI', 'C_1', 'C_B', 'C_E']\nName: ASPTYPE    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: BITPIX     Groupings: ['M_1', 'M_2', 'M_3', 'M_4']\nName: BTIMCORR   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_B', 'T_E']\nName: BTIMDRFT   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_B', 'T_E']\nName: BTIMNULL   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_B', 'T_E']\nName: BTIMRATE   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_B', 'T_E']\nName: CHECKSUM   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'C_1', 'C_2', 'C_3', 'C_B', 'C_E', 'C_P']\nName: CLOCKAPP   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: CONTENT    Groupings: ['C_1', 'C_2']\nName: CREATOR    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'C_1', 'C_2', 'C_3', 'C_B', 'C_E', 'C_P']\nName: CTI_APP    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: CTI_CORR   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: CYCLE      Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: DATACLAS   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DATAMODE   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DATASUM    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'C_1', 'C_2', 'C_3', 'C_B', 'C_E', 'C_P']\nName: DATE       Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: DATE-END   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: DATE-OBS   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: DEC_NOM    Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: DEC_PNT    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: DEC_TARG   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: DEFOCUS    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: DETNAM     Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DS_IDENT   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'O_1', 'O_3', 'O_B', 'O_E', 'O_P']\nName: DTCOR      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DTH_AVG    Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DY_AVG     Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DZ_AVG     Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: END        Groupings: ['M_1', 'M_2', 'M_3', 'M_4']\nName: EQUINOX    Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: EXPOSURE   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: EXTEND     Groupings: ['M_1', 'M_2']\nName: EXTNAME    Groupings: ['M_3', 'M_4']\nName: EXTVER     Groupings: ['M_3', 'M_4']\nName: FLSHTIME   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_B', 'T_E']\nName: FOC_LEN    Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: FP_TEMP    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: GCOUNT     Groupings: ['M_3', 'M_4']\nName: GRATING    Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: HDUCLAS1   Groupings: ['BASIC', 'EVENT', 'NONSI', 'C_1', 'C_2', 'C_B', 'C_E']\nName: HDUCLAS2   Groupings: ['BASIC', 'EVENT', 'NONSI', 'C_1', 'C_2', 'C_B', 'C_E']\nName: HDUCLAS3   Groupings: ['BASIC', 'EVENT', 'NONSI', 'C_1', 'C_2', 'C_B', 'C_E']\nName: HDUCLASS   Groupings: ['BASIC', 'EVENT', 'NONSI', 'C_1', 'C_2', 'C_B', 'C_E']\nName: HDUDOC     Groupings: ['C_1', 'C_2']\nName: HDUNAME    Groupings: ['C_1', 'C_2']\nName: HDUSPEC    Groupings: ['C_1']\nName: HDUVERS    Groupings: ['C_1', 'C_2']\nName: INSTRUME   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'O_1', 'O_3', 'O_4', 'O_B', 'O_E', 'O_P']\nName: LIVETIME   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: LONGSTRN   Groupings: ['C_1']\nName: MISSION    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'O_1', 'O_3', 'O_4', 'O_B', 'O_E', 'O_P']\nName: MJDREF     Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: MJD-OBS    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: NAXIS      Groupings: ['M_1', 'M_2', 'M_3', 'M_4']\nName: NAXIS1     Groupings: ['M_1', 'M_3', 'M_4']\nName: NAXIS2     Groupings: ['M_1', 'M_3', 'M_4']\nName: OBI_NUM    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'O_B', 'O_E', 'O_P']\nName: OBJECT     Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: OBSERVER   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: OBS_ID     Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'O_1', 'O_3', 'O_B', 'O_E', 'O_P']\nName: OBS_MODE   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: ONTIME     Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: ORIGIN     Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'C_1', 'C_2', 'C_3', 'C_B', 'C_E', 'C_P']\nName: PCOUNT     Groupings: ['M_3', 'M_4']\nName: RADESYS    Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: RAND_PI    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: RAND_SKY   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: RAND_TG    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: RA_NOM     Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: RA_PNT     Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: RA_TARG    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: READMODE   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: REVISION   Groupings: ['BASIC', 'EVENT', 'NONSI', 'C_1', 'C_B', 'C_E']\nName: ROLL_NOM   Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: ROLL_PNT   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: SEQ_NUM    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'O_1', 'O_3', 'O_B', 'O_E', 'O_P']\nName: SHYMINUS   Groupings: ['EVENT', 'O_E']\nName: SHYPLUS    Groupings: ['EVENT', 'O_E']\nName: SIMPLE     Groupings: ['M_1', 'M_2']\nName: SIM_X      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: SIM_Y      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: SIM_Z      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: STARTMJF   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: STARTMNF   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: STARTOBT   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: STOPMJF    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: STOPMNF    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: TASSIGN    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TELESCOP   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'O_1', 'O_3', 'O_4', 'O_B', 'O_E', 'O_P']\nName: TFIELDS    Groupings: ['M_3']\nName: TIERABSO   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIERRELA   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIMEDEL    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIMEPIXR   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIMEREF    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIMESYS    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: TIMEUNIT   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: TIMEZERO   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: TIMVERSN   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TITLE      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: TLMVER     Groupings: ['EVENT', 'C_1', 'C_E']\nName: TLM_FMT    Groupings: ['EVENT', 'O_E']\nName: TSTART     Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: TSTOP      Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: XTENSION   Groupings: ['M_3', 'M_4']\n\n"

        result = str(hdr)
        self.assertIn(result, expected, "print ALL keys FAILED")


        expected = "Name: ASPTYPE    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: BTIMCORR   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_B', 'T_E']\nName: BTIMDRFT   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_B', 'T_E']\nName: BTIMNULL   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_B', 'T_E']\nName: BTIMRATE   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_B', 'T_E']\nName: CHECKSUM   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'C_1', 'C_2', 'C_3', 'C_B', 'C_E', 'C_P']\nName: CLOCKAPP   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: CREATOR    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'C_1', 'C_2', 'C_3', 'C_B', 'C_E', 'C_P']\nName: CTI_APP    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: CTI_CORR   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: CYCLE      Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: DATACLAS   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DATAMODE   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DATASUM    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'C_1', 'C_2', 'C_3', 'C_B', 'C_E', 'C_P']\nName: DATE       Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: DATE-END   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: DATE-OBS   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: DEC_NOM    Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: DEC_PNT    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: DEC_TARG   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: DEFOCUS    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: DETNAM     Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DS_IDENT   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'O_1', 'O_3', 'O_B', 'O_E', 'O_P']\nName: DTCOR      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DTH_AVG    Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DY_AVG     Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: DZ_AVG     Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: EQUINOX    Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: EXPOSURE   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: FLSHTIME   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_B', 'T_E']\nName: FOC_LEN    Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: FP_TEMP    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: GRATING    Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: INSTRUME   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'O_1', 'O_3', 'O_4', 'O_B', 'O_E', 'O_P']\nName: LIVETIME   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: MISSION    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'O_1', 'O_3', 'O_4', 'O_B', 'O_E', 'O_P']\nName: MJDREF     Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: MJD-OBS    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: OBI_NUM    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'O_B', 'O_E', 'O_P']\nName: OBJECT     Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: OBSERVER   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: OBS_ID     Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'O_1', 'O_3', 'O_B', 'O_E', 'O_P']\nName: OBS_MODE   Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: ONTIME     Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: ORIGIN     Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'C_1', 'C_2', 'C_3', 'C_B', 'C_E', 'C_P']\nName: RADESYS    Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: RAND_PI    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: RAND_SKY   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: RAND_TG    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: RA_NOM     Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: RA_PNT     Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: RA_TARG    Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: READMODE   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: ROLL_NOM   Groupings: ['BASIC', 'EVENT', 'O_2', 'O_B', 'O_E']\nName: ROLL_PNT   Groupings: ['BASIC', 'EVENT', 'O_B', 'O_E']\nName: SEQ_NUM    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'O_1', 'O_3', 'O_B', 'O_E', 'O_P']\nName: SHYMINUS   Groupings: ['EVENT', 'O_E']\nName: SHYPLUS    Groupings: ['EVENT', 'O_E']\nName: SIM_X      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: SIM_Y      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: SIM_Z      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: STARTMJF   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: STARTMNF   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: STARTOBT   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: STOPMJF    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: STOPMNF    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_B', 'T_E']\nName: TASSIGN    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TELESCOP   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'O_1', 'O_3', 'O_4', 'O_B', 'O_E', 'O_P']\nName: TIERABSO   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIERRELA   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIMEDEL    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIMEPIXR   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIMEREF    Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TIMESYS    Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: TIMEUNIT   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: TIMEZERO   Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: TIMVERSN   Groupings: ['BASIC', 'EVENT', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_B', 'T_E']\nName: TITLE      Groupings: ['BASIC', 'EVENT', 'O_1', 'O_B', 'O_E']\nName: TLM_FMT    Groupings: ['EVENT', 'O_E']\nName: TSTART     Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\nName: TSTOP      Groupings: ['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']\n\n"


        hdr.build_hdr(["T_b","O_e","C_p"])

        result = str(hdr)
        self.assertIn(result, expected, "print [T_b, O_e, C_p] keys FAILED")


    def test_02(self):
        """
        Tests for CXCStandardHeader.get_key_groups()
            - empty CXCStandardHeader
            - CXCStandardHeader w/ BASIC keys
                - invalid input : <nothing>
                - invalid input : None
                - invalid input : integer 
                - invalid input : ""
                - invalid input : non-existent key
                - invalid input : valid key name

        """
        hdr = CXCStandardHeader()

        try:
            hdr.get_key_groups("ascdsver")
        except Exception as ex:
            if "This CXCHeader does not contain any keywords" not in str(ex):
                raise Exception("get_key_groups() FAILED")


        hdr.build_hdr("BASic")

        try:
            hdr.get_key_groups()
        except Exception as ex:
            if "missing 1 required positional argument" not in str(ex):
                raise Exception("get_key_groups() FAILED")

        try:
            hdr.get_key_groups(None)
        except Exception as ex:
            if "Please enter a key name" not in str(ex):
                raise Exception("get_key_groups(None) FAILED")

        try:
            hdr.get_key_groups(2)        
        except Exception as ex:
            if "Key name must be a string" not in str(ex):
                raise Exception("get_key_groups(2) FAILED")

        try:
            hdr.get_key_groups("")
        except Exception as ex:
            if "Key name cannot be an empty string" not in str(ex):
                raise Exception("get_key_groups('') FAILED")

        try:
            hdr.get_key_groups("foo")
        except Exception as ex:
            if "Key name does not exist in this header" not in str(ex):
                raise Exception("get_key_groups('foo') FAILED")

        expected = "['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'C_1', 'C_2', 'C_3', 'C_B', 'C_E', 'C_P']"

        result = hdr.get_key_groups("OrIgIn")
        self.assertIn( str(result), expected, "get_key_groups('OrIgIn') FAILED")


        expected = "['BASIC', 'EVENT', 'PRIMARY', 'NONSI', 'T_1', 'T_2', 'T_3', 'T_4', 'T_B', 'T_E', 'T_P']"
        result = hdr.get_key_groups("MJD-obs")
        self.assertIn( str(result), expected, "get_key_groups('MJD-obs') FAILED")



    def test_03(self):
        """
        Test for CXCStandardHeader.get_valid_groupings()
            - invalid input :  None
            - good input    :  <nothing>
        """

        hdr = CXCStandardHeader()

        try:
            hdr.get_valid_groupings(None)
        except Exception as ex:
            if "get_valid_groupings() takes 1 positional argument but 2 were given" not in str(ex):
                raise Exception("get_valid_groupings() FAILED") 


        expected = "['ALL', 'BASIC', 'EVENT', 'NONSI', 'C_1', 'C_B', 'C_E', 'O_B', 'O_E', 'M_1', 'M_2', 'M_3', 'M_4', 'T_1', 'T_2', 'T_B', 'T_E', 'PRIMARY', 'C_2', 'C_3', 'C_P', 'T_3', 'T_4', 'T_P', 'O_1', 'O_2', 'O_3', 'O_P', 'O_4']"

        result = hdr.get_valid_groupings()
        self.assertIn( str(result), expected, "get_valid_groupings() FAILED")


    def test_04(self):
        """
        Tests for CXCStandardHeader.get_keynames_list()
            - empty CXCStandardHeader
            - CXCStandardHeader w/ EVENT keys
                - invalid input : <nothing>
                - invalid input : None
                - invalid input :  "" 
                - invalid input :  list of strings, one valid, one invalid
                - invalid input :  two strings not contained in list
                - good input    :  <nothing>, default = "ALL"
                - good input    :  string
                - good input    :  list of strings
        """

        hdr = CXCStandardHeader()


        try:
            hdr.get_keynames_list()
        except Exception as ex:
            if "This CXCHeader does not contain any keywords" not in str(ex):
                raise Exception("get_keynames_list() FAILED")


        hdr.build_hdr("Event")

        try:
            hdr.get_keynames_list(None)
        except Exception as ex:
            if "Please specify header grouping(s)" not in str(ex):
                raise Exception("get_keynames_list(None) FAILED")

        try:
            hdr.get_keynames_list("")
        except Exception as ex:
            if "Please specify header grouping(s)" not in str(ex):
                raise Exception("get_keynames_list("") FAILED")

        try:
            hdr.get_keynames_list(["evENT", "FOO"])
        except Exception as ex:
            if "'FOO' is not a valid group" not in str(ex):
                raise Exception("get_keynames_list(['evENT', 'FOO']) FAILED")


        try:
            hdr.get_keynames_list("evENT", "FOO")
        except Exception as ex:
            if "et_keynames_list() takes from 1 to 2 positional arguments but 3 were given" not in str(ex):
                raise Exception("get_keynames_list('evENT', 'FOO') FAILED")



        expected = "['ASCDSVER', 'ASPTYPE', 'BTIMCORR', 'BTIMDRFT', 'BTIMNULL', 'BTIMRATE', 'CHECKSUM', 'CLOCKAPP', 'CREATOR', 'CTI_APP', 'CTI_CORR', 'CYCLE', 'DATACLAS', 'DATAMODE', 'DATASUM', 'DATE', 'DATE-END', 'DATE-OBS', 'DEC_NOM', 'DEC_PNT', 'DEC_TARG', 'DEFOCUS', 'DETNAM', 'DS_IDENT', 'DTCOR', 'DTH_AVG', 'DY_AVG', 'DZ_AVG', 'EQUINOX', 'EXPOSURE', 'FLSHTIME', 'FOC_LEN', 'FP_TEMP', 'GRATING', 'HDUCLAS1', 'HDUCLAS2', 'HDUCLAS3', 'HDUCLASS', 'INSTRUME', 'LIVETIME', 'MISSION', 'MJDREF', 'MJD-OBS', 'OBI_NUM', 'OBJECT', 'OBSERVER', 'OBS_ID', 'OBS_MODE', 'ONTIME', 'ORIGIN', 'RADESYS', 'RAND_PI', 'RAND_SKY', 'RAND_TG', 'RA_NOM', 'RA_PNT', 'RA_TARG', 'READMODE', 'REVISION', 'ROLL_NOM', 'ROLL_PNT', 'SEQ_NUM', 'SHYMINUS', 'SHYPLUS', 'SIM_X', 'SIM_Y', 'SIM_Z', 'STARTMJF', 'STARTMNF', 'STARTOBT', 'STOPMJF', 'STOPMNF', 'TASSIGN', 'TELESCOP', 'TIERABSO', 'TIERRELA', 'TIMEDEL', 'TIMEPIXR', 'TIMEREF', 'TIMESYS', 'TIMEUNIT', 'TIMEZERO', 'TIMVERSN', 'TITLE', 'TLMVER', 'TLM_FMT', 'TSTART', 'TSTOP']"

        result = hdr.get_keynames_list()
        self.assertIn( str(result), expected, "get_keynames_list() FAILED")


        expected = "['CHECKSUM', 'CREATOR', 'DATASUM', 'ORIGIN']"
        result = hdr.get_keynames_list("C_3")
        self.assertIn( str(result), expected, "get_keynames_list('C_3') FAILED")


        expected = "['ASCDSVER', 'BTIMCORR', 'BTIMDRFT', 'BTIMNULL', 'BTIMRATE', 'CHECKSUM', 'CLOCKAPP', 'CREATOR', 'DATASUM', 'DATE', 'DATE-END', 'DATE-OBS', 'DS_IDENT', 'FLSHTIME', 'HDUCLAS1', 'HDUCLAS2', 'HDUCLAS3', 'HDUCLASS', 'INSTRUME', 'INSTRUME', 'MISSION', 'MISSION', 'MJDREF', 'MJD-OBS', 'OBI_NUM', 'OBS_ID', 'ORIGIN', 'REVISION', 'SEQ_NUM', 'STARTMJF', 'STARTMNF', 'STARTOBT', 'STOPMJF', 'STOPMNF', 'TASSIGN', 'TELESCOP', 'TELESCOP', 'TIERABSO', 'TIERRELA', 'TIMEDEL', 'TIMEPIXR', 'TIMEREF', 'TIMESYS', 'TIMEUNIT', 'TIMEZERO', 'TIMVERSN', 'TSTART', 'TSTOP']"
        result = hdr.get_keynames_list(["NONsi", "O_p"])
        self.assertIn( str(result), expected, "get_keynames_list(['NONsi', 'O_p']) FAILED")



    def test_05(self):
        """
        Tests for JSON file environment variable $ASCDS_CALIB
            - invalid input : unset $ASCDS_CALIB
            - invalid input : $ASCDS_CALIB = ""
            - invalid input : unreadable JSON file
            - invalid input : _set_jsonfile(<int>)
        """
        ascds_calib_path = os.environ['ASCDS_CALIB']
        testout_path = os.environ['TESTOUT'] + "/pystdhdr"
        json_filename = "stdhdr_keys_template.json"

        if os.path.exists(testout_path + "/" + json_filename):
            os.system("rm " + testout_path + "/" + json_filename)
        os.system("cp " + ascds_calib_path + "/" + json_filename + " " + testout_path)
        os.system("chmod 222 " + testout_path + "/" + json_filename)

        try:
            del os.environ['ASCDS_CALIB'] 
            hdr = CXCStandardHeader()   
        except Exception as ex:
            if "Please set the $ASCDS_CALIB environment variable" not in (str(ex)):
                raise Exception("unset $ASCDS_CALIB test FAILED")

        try:
            os.environ['ASCDS_CALIB'] = ""
            hdr = CXCStandardHeader()   
        except Exception as ex:
            if "JSON file does not exist" not in str(ex):
                raise Exception("$ASCDS_CALIB='' test FAILED")  

        try:
            os.environ['ASCDS_CALIB'] = testout_path
            hdr = CXCStandardHeader()   
        except Exception as ex:
            if "JSON file is not readable. Please update the permissions." not in str(ex):
                raise Exception("unreadable JSON file test FAILED")  

        os.system("chmod 644 " + testout_path + "/" + json_filename)

        try:
            os.environ['ASCDS_CALIB'] = ascds_calib_path
            hdr = CXCStandardHeader()   
            hdr._set_jsonfile(int(22))
        except Exception as ex:
            if "Please input a valid JSON file" not in str(ex):
                raise Exception("hdr._set_jsonfile(22) FAILED")  


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