Ejemplo n.º 1
0
    def setUp(self):

        # retrieve OpEx data from Hahne et al.
        url = 'https://ndownloader.figshare.com/files/5201452'
        archive_fn = os.path.join(self.fp, os.path.basename(url))
        self.download_data(url) if not os.path.exists(archive_fn) else None
        self.fnames_wht_opex = [
            'f197with4m11pxf16Final.bmp', 'f197Inf9pxFinalShift12.7cmf22.bmp'
        ]
        self.fnames_lfp_opex = [
            'f197with4m11pxFinal.bmp', 'f197Inf9pxFinalShift12.7cm.bmp'
        ]
        self.extract_archive(os.path.join(self.fp, os.path.basename(url)),
                             self.fnames_wht_opex + self.fnames_lfp_opex)

        # set config for unit test purposes
        self.sta = PlenopticamStatus()
        self.cfg = PlenopticamConfig()
        self.cfg.reset_values()
        self.cfg.params[self.cfg.opt_dbug] = False
        self.cfg.params[
            self.cfg.
            opt_prnt] = False  # prevent Travis CI to terminate after reaching 4MB logfile size
        self.cfg.params[self.cfg.opt_vign] = False
        self.cfg.params[self.cfg.opt_sat_] = True
Ejemplo n.º 2
0
    def test_lfp(self):

        # set config for unit test purposes
        cfg = PlenopticamConfig()
        cfg.params[cfg.opt_dbug] = True

        for fn_lfp, fn_wht in zip(self.fnames_lfp, self.fnames_wht):

            # update file paths and calibration data in config
            cfg.params[cfg.lfp_path] = os.path.join(self.fp, fn_lfp)
            cfg.params[cfg.cal_path] = os.path.join(self.fp, fn_wht)
            cfg.params[cfg.cal_meta] = os.path.splitext(
                cfg.params[cfg.cal_path])[0] + '.json'
            cfg.load_cal_data()

            # create folder (if it doesn't already exist)
            misc.mkdir_p(os.path.splitext(cfg.params[cfg.lfp_path])[0])

            # test light field alignment
            lfp_img = misc.load_img_file(cfg.params[cfg.lfp_path])
            lfp_obj = LfpAligner(lfp_img=lfp_img, cfg=cfg, sta=None)
            ret_val = lfp_obj.main()
            lfp_img = lfp_obj.lfp_img
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)

            # test light field extraction
            lfp_obj = LfpExtractor(lfp_img_align=lfp_img, cfg=cfg, sta=None)
            ret_val = lfp_obj.main()
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)
Ejemplo n.º 3
0
    def test_cal(self):

        # set config for unit test purposes
        sta = PlenopticamStatus()
        cfg = PlenopticamConfig()
        cfg.reset_values()
        cfg.params[cfg.opt_dbug] = False
        cfg.params[
            cfg.
            opt_prnt] = False  # prevent Travis CI to terminate after reaching 4MB logfile size
        cfg.params[cfg.opt_vign] = False
        cfg.params[cfg.opt_sat_] = True

        for fn_lfp, fn_wht in zip(self.fnames_lfp, self.fnames_wht):

            # generate console output to prevent abort in Travis CI
            print(fn_wht)

            # update file paths and calibration data in config
            cfg.params[cfg.lfp_path] = os.path.join(self.fp, fn_lfp)
            cfg.params[cfg.cal_path] = os.path.join(self.fp, fn_wht)

            # create folder (if it doesn't already exist)
            mkdir_p(os.path.splitext(cfg.params[cfg.lfp_path])[0])

            # test light field calibration
            wht_img = load_img_file(cfg.params[cfg.cal_path])
            cal_obj = LfpCalibrator(wht_img=wht_img, cfg=cfg, sta=sta)
            ret_val = cal_obj.main()
            del cal_obj

            # assertion
            self.assertEqual(True, ret_val)
Ejemplo n.º 4
0
    def test_cal(self):

        # set config for unit test purposes
        sta = PlenopticamStatus()
        cfg = PlenopticamConfig()
        cfg.reset_values()
        cfg.params[cfg.opt_dbug] = False
        cfg.params[cfg.opt_prnt] = True

        for fn_lfp, fn_wht in zip(self.fnames_lfp, self.fnames_wht):

            # update file paths and calibration data in config
            cfg.params[cfg.lfp_path] = os.path.join(self.fp, fn_lfp)
            cfg.params[cfg.cal_path] = os.path.join(self.fp, fn_wht)

            # create folder (if it doesn't already exist)
            mkdir_p(os.path.splitext(cfg.params[cfg.lfp_path])[0])

            # test light field calibration
            wht_img = load_img_file(cfg.params[cfg.cal_path])
            cal_obj = LfpCalibrator(wht_img=wht_img, cfg=cfg, sta=sta)
            ret_val = cal_obj.main()
            del cal_obj

            # assertion
            self.assertEqual(True, ret_val)
Ejemplo n.º 5
0
    def setUp(self):

        # set config for unit test purposes
        self.sta = PlenopticamStatus()
        self.cfg = PlenopticamConfig()
        self.cfg.reset_values()
        self.cfg.params[self.cfg.opt_dbug] = True
        self.cfg.params[self.cfg.opt_prnt] = True
Ejemplo n.º 6
0
    def setUp(self):

        # set config for unit test purposes
        self.sta = PlenopticamStatus()
        self.cfg = PlenopticamConfig()
        self.cfg.reset_values()
        self.cfg.params[self.cfg.opt_dbug] = False
        self.cfg.params[
            self.cfg.
            opt_prnt] = False  # prevent Travis CI to terminate after reaching 4MB logfile size
        self.cfg.params[self.cfg.opt_vign] = False
        self.cfg.params[self.cfg.opt_sat_] = True
Ejemplo n.º 7
0
    def setUp(self):

        # set config for unit test purposes
        self.sta = PlenopticamStatus()
        self.cfg = PlenopticamConfig()
        self.cfg.reset_values()
        self.cfg.params[self.cfg.opt_dbug] = False
        self.cfg.params[self.cfg.opt_prnt] = False    # prevent Travis CI to terminate after reaching 4MB logfile size
        self.cfg.params[self.cfg.opt_vign] = True
        self.cfg.params[self.cfg.opt_sat_] = True

        # retrieve OpEx data from Hahne et al.
        self.loader = DataDownloader(cfg=self.cfg, sta=self.sta)
        self.fp = join(self.loader.root_path, 'examples', 'data')
        archive_fn = join(self.fp, basename(self.loader.opex_url))
        self.loader.download_data(self.loader.opex_url, fp=self.fp) if not exists(archive_fn) else None
        self.loader.extract_archive(archive_fn, self.loader.opex_fnames_wht + self.loader.opex_fnames_lfp)
Ejemplo n.º 8
0
class PlenoptiCamTesterCustom(PlenoptiCamTester):
    def __init__(self, *args, **kwargs):
        super(PlenoptiCamTesterCustom, self).__init__(*args, **kwargs)

    def setUp(self):

        # set config for unit test purposes
        self.sta = PlenopticamStatus()
        self.cfg = PlenopticamConfig()
        self.cfg.reset_values()
        self.cfg.params[self.cfg.opt_dbug] = False
        self.cfg.params[
            self.cfg.
            opt_prnt] = False  # prevent Travis CI to terminate after reaching 4MB logfile size
        self.cfg.params[self.cfg.opt_vign] = False
        self.cfg.params[self.cfg.opt_sat_] = True

    def test_viewer(self):

        try:
            import tkinter as tk
        except ImportError:
            import Tkinter as tk

        # dummy button with state key
        btn = {'state': 'normal'}

        # instantiate viewer
        self.view_frame = tk.Toplevel(padx=PX, pady=PY)  # open window
        self.view_frame.resizable(width=0,
                                  height=0)  # make window not resizable
        ViewWidget(self.view_frame, cfg=self.cfg, sta=self.sta,
                   btn=btn).pack(expand="no", fill="both")

        # close frame
        self.view_frame.destroy()

        return True
Ejemplo n.º 9
0
    def test_cli_cmd_opts(self):

        from plenopticam.bin.cli_script import parse_options
        from plenopticam.cfg import PlenopticamConfig
        from plenopticam.cfg.constants import PARAMS_KEYS

        cfg = PlenopticamConfig()

        exp_vals = ['dummy.ext', 'wht.ext', None, 'grid-fit', 9, [0, 3], None
                    ] + [
                        True,
                    ] * 3 + [
                        None,
                        True,
                        True,
                        None,
                        None,
                        True,
                        None,
                        True,
                    ] + [
                        None,
                    ] * 4
        usr_cmds = [
            "--file=", "--cali=", "--meta=", "--meth=", "--patch=", "--refo=",
            "--copt", "--vgn", "--hot", "--con", "--col", "--awb", "--sat",
            "--view", "--refo", "--refi", "--pflu", "--art", "--rot", "--dbg",
            "--prt", "--rem"
        ]

        for cmd, kw, exp_val in zip(usr_cmds, PARAMS_KEYS, exp_vals):

            # pass CLI argument to
            exp_str = '"' + exp_val + '"' if isinstance(exp_val,
                                                        str) else exp_val
            cli_str = cmd + str(exp_str) if type(exp_val) in (str, int,
                                                              list) else cmd
            sys.argv.append(cli_str)
            print(cli_str)
            try:
                cfg = parse_options(sys.argv[1:], cfg)
                val = cfg.params[kw]
            except SystemExit:
                val = None
            sys.argv.pop()

            self.assertEqual(exp_val, val)
Ejemplo n.º 10
0
    def test_lfp(self):

        # set config for unit test purposes
        sta = PlenopticamStatus()
        cfg = PlenopticamConfig()
        cfg.reset_values()
        cfg.params[cfg.opt_dbug] = False
        cfg.params[
            cfg.
            opt_prnt] = False  # prevent Travis CI to terminate after reaching 4MB logfile size

        for fn_lfp, fn_wht in zip(self.fnames_lfp, self.fnames_wht):

            # generate console output to prevent abort in Travis CI
            print(fn_lfp)

            # update file paths and calibration data in config
            cfg.params[cfg.lfp_path] = os.path.join(self.fp, fn_lfp)
            cfg.params[cfg.cal_path] = os.path.join(self.fp, fn_wht)
            cfg.params[cfg.cal_meta] = os.path.splitext(
                cfg.params[cfg.cal_path])[0] + '.json'
            cfg.load_cal_data()

            # create folder (if it doesn't already exist)
            mkdir_p(os.path.splitext(cfg.params[cfg.lfp_path])[0])

            # test light field alignment
            lfp_img = load_img_file(cfg.params[cfg.lfp_path])
            lfp_obj = LfpAligner(lfp_img=lfp_img, cfg=cfg, sta=sta)
            ret_val = lfp_obj.main()
            lfp_img = lfp_obj.lfp_img
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)

            # test light field extraction
            lfp_obj = LfpExtractor(lfp_img_align=lfp_img, cfg=cfg, sta=sta)
            lfp_obj.main()
            vp_img_arr = lfp_obj.vp_img_arr
            del lfp_obj

            lfp_obj = LfpRefocuser(vp_img_arr=vp_img_arr, cfg=cfg, sta=sta)
            lfp_obj.main()
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)
Ejemplo n.º 11
0
class PlenoptiCamTesterCustom(PlenoptiCamTester):
    def __init__(self, *args, **kwargs):
        super(PlenoptiCamTesterCustom, self).__init__(*args, **kwargs)

    def setUp(self):

        # retrieve OpEx data from Hahne et al.
        url = 'https://ndownloader.figshare.com/files/5201452'
        archive_fn = os.path.join(self.fp, os.path.basename(url))
        self.download_data(url) if not os.path.exists(archive_fn) else None
        self.fnames_wht_opex = [
            'f197with4m11pxf16Final.bmp', 'f197Inf9pxFinalShift12.7cmf22.bmp'
        ]
        self.fnames_lfp_opex = [
            'f197with4m11pxFinal.bmp', 'f197Inf9pxFinalShift12.7cm.bmp'
        ]
        self.extract_archive(os.path.join(self.fp, os.path.basename(url)),
                             self.fnames_wht_opex + self.fnames_lfp_opex)

        # set config for unit test purposes
        self.sta = PlenopticamStatus()
        self.cfg = PlenopticamConfig()
        self.cfg.reset_values()
        self.cfg.params[self.cfg.opt_dbug] = False
        self.cfg.params[
            self.cfg.
            opt_prnt] = False  # prevent Travis CI to terminate after reaching 4MB logfile size
        self.cfg.params[self.cfg.opt_vign] = False
        self.cfg.params[self.cfg.opt_sat_] = True

    def test_custom_cal(self):

        for fn_lfp, fn_wht in zip(self.fnames_lfp_opex, self.fnames_wht_opex):

            # generate console output to prevent abort in Travis CI
            print(fn_wht)

            # update file paths and calibration data in config
            self.cfg.params[self.cfg.lfp_path] = os.path.join(self.fp, fn_lfp)
            self.cfg.params[self.cfg.cal_path] = os.path.join(self.fp, fn_wht)

            # create folder (if it doesn't already exist)
            mkdir_p(os.path.splitext(self.cfg.params[self.cfg.lfp_path])[0])

            # test light field calibration
            wht_img = load_img_file(self.cfg.params[self.cfg.cal_path])
            cal_obj = LfpCalibrator(wht_img=wht_img,
                                    cfg=self.cfg,
                                    sta=self.sta)
            ret_val = cal_obj.main()
            del cal_obj

            # assertion
            self.assertEqual(True, ret_val)

    def test_custom_lfp(self):

        for fn_lfp, fn_wht in zip(self.fnames_lfp_opex, self.fnames_wht_opex):

            # generate console output to prevent abort in Travis CI
            print(fn_lfp)

            # update file paths and calibration data in config
            self.cfg.params[self.cfg.lfp_path] = os.path.join(self.fp, fn_lfp)
            self.cfg.params[self.cfg.cal_path] = os.path.join(self.fp, fn_wht)
            self.cfg.params[self.cfg.cal_meta] = os.path.splitext(
                self.cfg.params[self.cfg.cal_path])[0] + '.json'
            self.cfg.load_cal_data()

            # create folder (if it doesn't already exist)
            mkdir_p(os.path.splitext(self.cfg.params[self.cfg.lfp_path])[0])

            # test light field alignment
            lfp_img = load_img_file(self.cfg.params[self.cfg.lfp_path])
            lfp_obj = LfpAligner(lfp_img=lfp_img, cfg=self.cfg, sta=self.sta)
            ret_val = lfp_obj.main()
            lfp_img = lfp_obj.lfp_img
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)

            # test light field extraction
            lfp_obj = LfpExtractor(lfp_img_align=lfp_img,
                                   cfg=self.cfg,
                                   sta=self.sta)
            ret_val = lfp_obj.main()
            vp_img_arr = lfp_obj.vp_img_arr
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)

            lfp_obj = LfpRefocuser(vp_img_arr=vp_img_arr,
                                   cfg=self.cfg,
                                   sta=self.sta)
            ret_val = lfp_obj.main()
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)
Ejemplo n.º 12
0
class PlenoptiCamTesterCustom(PlenoptiCamTester):

    CEA_PATH = r'../plenopticam/scripts/metrics/calibration/centroid_error_analysis/'

    def __init__(self, *args, **kwargs):
        super(PlenoptiCamTesterCustom, self).__init__(*args, **kwargs)

    def setUp(self):

        # retrieve OpEx data from Hahne et al.
        url = 'https://ndownloader.figshare.com/files/5201452'
        archive_fn = join(self.fp, basename(url))
        self.download_data(url) if not exists(archive_fn) else None
        self.fnames_wht_opex = ['f197with4m11pxf16Final.bmp', 'f197Inf9pxFinalShift12.7cmf22.bmp']
        self.fnames_lfp_opex = ['f197with4m11pxFinal.bmp', 'f197Inf9pxFinalShift12.7cm.bmp']
        self.extract_archive(join(self.fp, basename(url)), self.fnames_wht_opex+self.fnames_lfp_opex)

        # set config for unit test purposes
        self.sta = PlenopticamStatus()
        self.cfg = PlenopticamConfig()
        self.cfg.reset_values()
        self.cfg.params[self.cfg.opt_dbug] = False
        self.cfg.params[self.cfg.opt_prnt] = False    # prevent Travis CI to terminate after reaching 4MB logfile size
        self.cfg.params[self.cfg.opt_vign] = True
        self.cfg.params[self.cfg.opt_sat_] = True

    def test_custom_cal(self):

        for fn_lfp, fn_wht in zip(self.fnames_lfp_opex, self.fnames_wht_opex):

            # generate console output to prevent abort in Travis CI
            print(fn_wht)

            # update file paths and calibration data in config
            self.cfg.params[self.cfg.lfp_path] = join(self.fp, fn_lfp)
            self.cfg.params[self.cfg.cal_path] = join(self.fp, fn_wht)

            # create folder (if it doesn't already exist)
            mkdir_p(splitext(self.cfg.params[self.cfg.lfp_path])[0])

            # test light field calibration
            wht_img = load_img_file(self.cfg.params[self.cfg.cal_path])
            cal_obj = LfpCalibrator(wht_img=wht_img, cfg=self.cfg, sta=self.sta)
            ret_val = cal_obj.main()
            del cal_obj

            # assertion
            self.assertEqual(True, ret_val)

    def test_custom_lfp(self):

        for fn_lfp, fn_wht in zip(self.fnames_lfp_opex, self.fnames_wht_opex):

            # generate console output to prevent abort in Travis CI
            print(fn_lfp)

            # update file paths and calibration data in config
            self.cfg.params[self.cfg.lfp_path] = join(self.fp, fn_lfp)
            self.cfg.params[self.cfg.cal_path] = join(self.fp, fn_wht)
            self.cfg.params[self.cfg.cal_meta] = splitext(self.cfg.params[self.cfg.cal_path])[0]+'.json'
            self.cfg.load_cal_data()

            # create folder (if it doesn't already exist)
            mkdir_p(splitext(self.cfg.params[self.cfg.lfp_path])[0])

            # test light field alignment
            lfp_img = load_img_file(self.cfg.params[self.cfg.lfp_path])
            lfp_obj = LfpAligner(lfp_img=lfp_img, cfg=self.cfg, sta=self.sta)
            ret_val = lfp_obj.main()
            lfp_img = lfp_obj.lfp_img
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)

            # test light field extraction
            lfp_obj = LfpExtractor(lfp_img_align=lfp_img, cfg=self.cfg, sta=self.sta)
            ret_val = lfp_obj.main()
            vp_img_arr = lfp_obj.vp_img_arr
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)

            lfp_obj = LfpRefocuser(vp_img_arr=vp_img_arr, cfg=self.cfg, sta=self.sta)
            ret_val = lfp_obj.main()
            del lfp_obj

            # assertion
            self.assertEqual(True, ret_val)

    @unittest.skipUnless(condition=exists(join(CEA_PATH, 'a.png')), reason='Test data for PitchEstimator not found')
    def test_pitch_estimator(self):

        from plenopticam.lfp_calibrator import PitchEstimator

        fns = [join(self.CEA_PATH, fn+'.png') for fn in ['a', 'b', 'c', 'd']]
        ref_sizes = [141, 50, 10, 6]

        for fn, ref_size in zip(fns, ref_sizes):
            img = load_img_file(fn)
            obj = PitchEstimator(img=img, cfg=self.cfg)
            obj.main()

            self.assertEqual(ref_size, obj.M)
Ejemplo n.º 13
0
    def test_illum(self):

        # instantiate config and status objects
        cfg = PlenopticamConfig()
        cfg.default_values()
        sta = PlenopticamStatus()

        # skip concole output message (prevent Travis from terminating due to reaching 4MB logfile size)
        cfg.params[cfg.opt_prnt] = False

        # use pre-loaded calibration dataset
        wht_list = [file for file in os.listdir(self.fp) if file.startswith('caldata')]
        lfp_list = [file for file in os.listdir(self.fp) if file.endswith(('lfr', 'lfp'))]

        cfg.params[cfg.cal_path] = os.path.join(self.fp, wht_list[0])

        for lfp_file in lfp_list:

            print('Compute image %s' % os.path.basename(cfg.params[cfg.lfp_path]))
            cfg.params[cfg.lfp_path] = os.path.join(self.fp, lfp_file)

            # decode light field image
            lfp_obj = LfpReader(cfg, sta)
            ret_val = lfp_obj.main()
            lfp_img = lfp_obj.lfp_img
            del lfp_obj

            self.assertEqual(True, ret_val)

            # create output data folder
            mkdir_p(cfg.exp_path, cfg.params[cfg.opt_prnt])

            if not cfg.cond_meta_file():
                # automatic calibration data selection
                obj = CaliFinder(cfg, sta)
                ret_val = obj.main()
                wht_img = obj.wht_bay
                del obj

                self.assertEqual(True, ret_val)

            meta_cond = not (os.path.exists(cfg.params[cfg.cal_meta]) and cfg.params[cfg.cal_meta].lower().endswith('json'))
            if meta_cond or cfg.params[cfg.opt_cali]:
                # perform centroid calibration
                cal_obj = LfpCalibrator(wht_img, cfg, sta)
                ret_val = cal_obj.main()
                cfg = cal_obj.cfg
                del cal_obj

                self.assertEqual(True, ret_val)

            # load calibration data
            cfg.load_cal_data()

            #  check if light field alignment has been done before
            if cfg.cond_lfp_align():
                # align light field
                lfp_obj = LfpAligner(lfp_img, cfg, sta, wht_img)
                ret_val = lfp_obj.main()
                lfp_obj = lfp_obj.lfp_img
                del lfp_obj

                self.assertEqual(True, ret_val)

            # load previously computed light field alignment
            with open(os.path.join(cfg.exp_path, 'lfp_img_align.pkl'), 'rb') as f:
                lfp_img_align = pickle.load(f)

            # extract viewpoint data
            CaliFinder(cfg).main()
            obj = LfpExtractor(lfp_img_align, cfg=cfg, sta=sta)
            ret_val = obj.main()
            vp_img_arr = obj.vp_img_arr
            del obj

            self.assertEqual(True, ret_val)

            # do refocusing
            if cfg.params[cfg.opt_refo]:
                obj = LfpRefocuser(vp_img_arr, cfg=cfg, sta=sta)
                ret_val = obj.main()
                del obj

            self.assertEqual(True, ret_val)

        return True
Ejemplo n.º 14
0
class PlenoptiCamTesterUI(PlenoptiCamTester):
    def __init__(self, *args, **kwargs):
        super(PlenoptiCamTesterUI, self).__init__(*args, **kwargs)

    def setUp(self):

        # set config for unit test purposes
        self.sta = PlenopticamStatus()
        self.cfg = PlenopticamConfig()
        self.cfg.reset_values()
        self.cfg.params[self.cfg.opt_dbug] = True
        self.cfg.params[self.cfg.opt_prnt] = True

    def test_cli_help(self):

        for kw in ['-h', '--help']:
            # print help message
            sys.argv.append(kw)
            try:
                ret = main()
            except SystemExit:
                ret = True

            self.assertEqual(True, ret)

    def test_cli_cmd_opts(self):

        from plenopticam.bin.cli_script import parse_options
        from plenopticam.cfg import PlenopticamConfig
        from plenopticam.cfg.constants import PARAMS_KEYS

        cfg = PlenopticamConfig()

        exp_vals = ['dummy.ext', 'wht.ext', None, 'grid-fit', 9, [0, 3], None
                    ] + [
                        True,
                    ] * 3 + [
                        None,
                        True,
                        True,
                        None,
                        None,
                        True,
                        None,
                        True,
                    ] + [
                        None,
                    ] * 4
        usr_cmds = [
            "--file=", "--cali=", "--meta=", "--meth=", "--patch=", "--refo=",
            "--copt", "--vgn", "--hot", "--con", "--col", "--awb", "--sat",
            "--view", "--refo", "--refi", "--pflu", "--art", "--rot", "--dbg",
            "--prt", "--rem"
        ]

        for cmd, kw, exp_val in zip(usr_cmds, PARAMS_KEYS, exp_vals):

            # pass CLI argument to
            exp_str = '"' + exp_val + '"' if isinstance(exp_val,
                                                        str) else exp_val
            cli_str = cmd + str(exp_str) if type(exp_val) in (str, int,
                                                              list) else cmd
            sys.argv.append(cli_str)
            print(cli_str)
            try:
                cfg = parse_options(sys.argv[1:], cfg)
                val = cfg.params[kw]
            except SystemExit:
                val = None
            sys.argv.pop()

            self.assertEqual(exp_val, val)

    def test_viewer(self):

        try:
            import tkinter as tk
        except ImportError:
            import Tkinter as tk

        # dummy button with state key
        btn = {'state': 'normal'}

        # instantiate viewer
        self.view_frame = tk.Toplevel(padx=PX, pady=PY)  # open window
        self.view_frame.resizable(width=0,
                                  height=0)  # make window not resizable
        ViewWidget(self.view_frame, cfg=self.cfg, sta=self.sta,
                   btn=btn).pack(expand="no", fill="both")

        # close frame
        self.view_frame.destroy()

        return True