def testprocessLoop(self):
     ui = userinput.UserInput(dlxii.Device())
     ui.comm_port = Testutils.sdevice
     utili = utils.Utils(ui,
                         controller.Controller(ui),
                         testing=True,
                         showhelp=False)
     utili.process_loop()
Beispiel #2
0
    def testrequest(self):
        fakeuser = ['', 'wrongport']
        try:
            ui = userinput.UserInput(dlxii.Device(), testdata=fakeuser)
            ui.request()
            self.assertTrue(False, msg="did not fault on empty debug list")
        except IndexError:
            pass

        ports = getports.GetPorts().get()
        fakeuser += getports.GetPorts().get() + \
            ['junk', 'dlx2', 'mytest.txt']
        ui = userinput.UserInput(dlxii.Device(), testdata=fakeuser)
        ui.request()
        self.assertEqual(ports[0], ui.comm_port)
        self.assertEqual('mytest.txt', ui.inputfn)
        self.assertTrue(isinstance(ui.controller_type, dlxii.Device))
 def testcreation(self):
     ui = userinput.UserInput(dlxii.Device())
     ui.comm_port = Testutils.sdevice
     c = controller.Controller(ui)
     utili = utils.Utils(ui, c, testing=False, showhelp=False)
     self.assertFalse(utili.testing)
     utili = utils.Utils(ui, c, testing=True, showhelp=False)
     self.assertTrue(utili.testing)
     utili = utils.Utils(ui, c, testing=True, showhelp=True)
 def testresetCmdNames(self):
     ui = userinput.UserInput(dlxii.Device())
     ui.comm_port = Testutils.sdevice
     utili = utils.Utils(ui,
                         controller.Controller(ui),
                         testing=True,
                         showhelp=False)
     myserial.MySerial._dbidx = -1
     utili.reset_cmd_names()
Beispiel #5
0
 def setUp(self):
     myclass = myserial.MySerial
     sp = myclass(dlxii.Device())
     sp.port = TestMySerial.sdevice
     sp.baudrate = 9600
     sp.timeout = 1.5
     sp.open()
     if sp.isOpen():
         sp.close()
     TestMySerial.gsp = sp
     myclass._debugging = True
 def testcreation(self):
     """tbd"""
     cs = dlxii.Device()
     self.assertEqual('RLC-Club Deluxe II v2.15', cs.get_Ctr_type)
     cpsData = cs.cps_data
     cps0 = cpsData[0]
     self.assertEqual('[CPS: 960, 0.215]', str(cps0))
     self.assertEqual(9600, cps0.bps)
     self.assertTrue(0.21 < cps0.cpsDelay < 0.22)
     ss = '[CPS: 960, 0.215]'
     self.assertEqual(ss, str(cps0))
     rates = [d.bps for d in cs.cps_data]
     self.assertEqual([9600, 19200, 4800, 2400, 1200, 600, 300], rates)
     css = 'RLC-Club Deluxe II v2.15'
     self.assertEqual(css, str(cs))
    def teststr(self):
        ui = userinput.UserInput(dlxii.Device())
        ui.comm_port = Testutils.sdevice
        c = controller.Controller(ui)
        utili = utils.Utils(ui, c, testing=False, showhelp=False)
        self.assertEqual(
            'testing:False, cmds: -acr, -rmn, -ran, -rmd, -cacn, -q',
            str(utili))
        utili = utils.Utils(ui, c, testing=True, showhelp=False)
        self.assertEqual(
            'testing:True, cmds: -acr, -rmn, -ran, -rmd, -cacn, -q',
            str(utili))

        # if showhelp true then something like
        """
    def testfmt_rcm(self):
        cs = dlxii.Device()
        r = cs.fmtRMC("junk test")
        self.assertEqual("junk test", r[0])
        self.assertEqual({}, r[1])
        mdf = """OK
DTMF>N011 521N011521
Command number 521 is named C47571.  It takes 0 digits of data.
OK
OK
DTMF>"""
        _ = cs.fmtRCM(mdf)
        self.assertEqual(
            'Command number 521 is named C47571.  It takes 0 digits of data.',
            _[0])
        self.assertEqual(3, len(_[1]))
Beispiel #9
0
    def testopen(self):
        """testopen()
        """
        self.assertTrue(myserial.MySerial._debugging)
        ui = userinput.UserInput(dlxii.Device())
        ui.inputfn = "cmdreadertest.txt"
        ui.comm_port = Testuserinput.sdevice
        self.assertTrue(ui.open(detect_br=False))
        sp = ui.serial_port
        self.assertTrue(sp.isOpen())
        self.assertEqual(Testuserinput.sdevice, sp.port)
        self.assertEqual(9600, sp.baudrate)
        ui.close()
        ui.close()
        self.assertFalse(sp.isOpen())
        self.assertFalse(ui.serial_port.isOpen())
        # prep for test with baudrate finder
        myserial.MySerial._dbidx = 0
        myserial.MySerial._debugreturns = [
            b'preread ignored', b'9600 fail try 1 MF>', b'preread ignored',
            b'9600 fail try 2 MF>', b'preread ignored',
            b'19200 fail try 1 TMF>', b'preread ignored',
            b'19200 succeed try 2 DTMF>'
        ]

        self.assertTrue(ui.open())
        self.assertEqual(19200, sp.baudrate)
        self.assertTrue(sp.isOpen())
        ui.close()

        myserial.MySerial._debugreturns = [
            b'preread ignored', b'9600 fail try 1 MF>', b'preread ignored',
            b'9600 fail try 2 MF>', b'preread ignored',
            b'19200 fail try 1 TMF>', b'preread ignored',
            b'19200 succeed try 2 DTMF>'
        ]
        myserial.MySerial._dbidx = 0

        ui.open(detect_br=False)
        self.assertEqual(9600, sp.baudrate)  # 9600 is the default
        ui.close()
    def testfmt_rmc(self):
        cs = dlxii.Device()
        r = cs.fmtRMC("junk test")
        self.assertEqual("junk test", r[0])
        self.assertEqual({}, r[1])
        mdf = """DTMF>N054 501N054501
Macro 501 contains 2 commands:
  #00  Command #038 with 00 digits of data:
  #01  Command #000 with 02 digits of data: 13
This macro is 9 percent full
OK
OK
DTMF>"""
        r = cs.fmtRMC(mdf)
        self.assertEqual(
            'Macro 501 contains 2 commands\n'
            '#00  Command #038 with 00 digits of data:\n'
            '#01  Command #000 with 02 digits of data: 13\n'
            'This macro is 9 percent full', r[0])
        self.assertEqual(4, len(r[1]))
        self.assertEqual(2, len(r[1].get("cmds")))
Beispiel #11
0
    def testcheckdate(self):

        cs = dlxii.Device()
        tup = cs.newcmd_dict['gdate']
        self.assertEqual('N029', tup[0])
        pat = tup[1]
        mdf = """total crap >"""
        mx = pat.search(mdf)
        self.assertFalse(mx)

        mdf = """DTMF>N029
This is Wednesday, 01-03-2018
OK
DTMF>"""
        mx = pat.search(mdf)
        _res = tup[2](mx)
        sdtpl = cs.newcmd_dict['sdate']
        matchtime = time.strptime("03 Jan 2018 11 30 30", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_date(_res, sdtpl, matchtime)
        self.assertFalse(cd)

        matchtime = time.strptime("03 Jan 2017 11 30 30", "%d %b %Y %H %M %S")
        cd = updatetime.check_date(_res, sdtpl, matchtime)
        self.assertEqual('N0280103173', cd)

        matchtime = time.strptime("01 Jan 2018 11 30 30", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_date(_res, sdtpl, matchtime)
        self.assertEqual('N0280101182', cd)

        matchtime = time.strptime("01 Feb 2018 11 30 30", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_date(_res, sdtpl, matchtime)
        self.assertEqual('N0280201185', cd)

        matchtime = time.strptime("01 Jan 2018 11 30 30", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_date(_res, sdtpl, matchtime)
        self.assertEqual('N0280101182', cd)
    def test1_open(self):
        """testopen()

        """
        _cr = CommandReader(TestCommandreader.ui)
        _fcr = None
        try:
            self.assertTrue(_cr.atts['is_closed'])
            self.assertEqual("", _cr.get())
            _cr.close()
            self.assertTrue(_cr.open())

            eres = '[CommandReader closed: False, [UserInput: , cmdreadertest.txt]]'
            self.assertEqual(eres, str(_cr))
            self.assertEqual(eres, repr(_cr))

            self.assertFalse(_cr.atts['is_closed'])
            try:
                _cr.open()
                assert "did not detect multiple attempts to open"
            except AssertionError:
                pass

            _cr.close()
            self.assertTrue(_cr.atts['is_closed'])
            fakeui = userinput.UserInput(dlxii.Device())
            fakeui.inputfn = 'totaljunk.txt'
            _fcr = CommandReader(fakeui)
            self.assertFalse(_fcr.open())
            self.assertEqual(
                "[Errno 2] No such file or directory: 'totaljunk.txt'",
                str(_fcr.atts['lasterror']))
            self.assertTrue(_fcr.atts['is_closed'])
        finally:
            if _fcr:
                _fcr.close()

            _cr.close()
Beispiel #13
0
    def testdoit(self):
        msclass = myserial.MySerial
        devs: List[str] = getports.GetPorts().get()
        port = 'COM3'
        if devs:
            port = devs[0]
        else:
            self.fail('no ports available')

        msclass._debugging = True
        msclass._dbidx = 0  # test same date and time
        msclass._debugreturns = [
            b'preread ignored\r',
            b'\n9600 open default succeed DTMF>',
            b'DTMF>N029\r',
            b'\nThis is Wednesday, 01-03-2018\r',
            b'\nOK\r',
            b'\nDTMF>',
            b'DTMF>N027\r',
            b'\nThe time is 12:23 P.M.\r',
            b'\nOK\r',
            b'\nDTMF>',
        ]

        ui = userinput.UserInput(ctype=dlxii.Device())
        ui.controller_type = dlxii.Device()
        ui.comm_port = port
        ui.inputfn = 'updatetest.txt'
        matchtime = time.strptime("03 Jan 2018 12 23 00", "%d %b %Y %H %M %S")
        stuff = updatetime.Stuff((ui, False, False))
        res = stuff.doit(debug_time=matchtime)
        self.assertTrue(res[2])
        self.assertEqual(14, res[0])
        self.assertTrue(14, res[1])

        msclass._dbidx = 0  # test same date differnt time
        msclass._debugreturns = [
            b'preread ignored\r',
            b'\n9600 open default succeed DTMF>',
            b'DTMF>N029\r',
            b'\nThis is Wednesday, 01-03-2018\r',
            b'\nOK\r',
            b'\nDTMF>',
            b'DTMF>N027\r',
            b'\nThe time is 12:23 P.M.\r',
            b'\nOK\r',
            b'\nDTMF>',
            b'DTMF>N02507071\r',
            b'\nTime set to 12:02 P.M.\r',
            b'\nOK\r',
            b'\nOK\r',
            b'\nDTMF>',
            b'DTMF>N029\r',
            b'\nThis is Wednesday, 01-03-2018\r',
            b'\nOK\r',
            b'\nDTMF>',
            b'DTMF>N027\r',
            b'\nThe time is 12:02 P.M.\r',
            b'\nOK\r',
            b'\nDTMF>',
            b'\nDTMF>',
            b'\nDTMF>',
            b'\nDTMF>',
            b'\nDTMF>',
            b'\nDTMF>',
            b'\nDTMF>',
            b'\nDTMF>',
        ]
        matchtime = time.strptime("03 Jan 2018 12 02 00", "%d %b %Y %H %M %S")
        res = stuff.doit(debug_time=matchtime)
        self.assertTrue(res[1])
        self.assertEqual(13, res[0])
        self.assertFalse(res[2])

        msclass._dbidx = 0  # test differnt time and different date
        msclass._debugreturns = [
            b'preread ignored\r',
            b'\n9600 open default succeed DTMF>',
            b'DTMF>N029\r',
            b'\nThis is Tuesday, 01-02-2018\r',
            b'\nOK\r',
            b'\nDTMF>',
            b'DTMF>N0280103184\r',
            b'\nThis is Wednesday, 01-03-2018\r',
            b'\nOK\r',
            b'\nDTMF>',
            b'DTMF>N029\r',
            b'\nThis is Wednesday, 01-03-2018\r',
            b'\nOK\r',
            b'\nDTMF>',
            b'DTMF>N027\r',
            b'\nThe time is 12:23 P.M.\r',
            b'\nOK\r',
            b'\nDTMF>',
            b'DTMF>N02507071\r',
            b'\nTime set to 12:02 P.M.\r',
            b'\nOK\r',
            b'\nOK\r',
            b'\nDTMF>',
            b'DTMF>N029\r',
            b'\nThis is Wednesday, 01-03-2018\r',
            b'\nOK\r',
            b'\nDTMF>',
            b'DTMF>N027\r',
            b'\nThe time is 12:02 P.M.\r',
            b'\nOK\r',
            b'\nDTMF>',
            b'\nDTMF>',
            b'\nDTMF>',
            b'\nDTMF>',
            b'\nDTMF>',
            b'\nDTMF>',
            b'\nDTMF>',
            b'\nDTMF>',
        ]
        matchtime = time.strptime("03 Jan 2018 12 02 00", "%d %b %Y %H %M %S")
        res = stuff.doit(debug_time=matchtime)
        self.assertTrue(res[1])
        self.assertEqual(12, res[0])
        self.assertFalse(res[2])
        # still need to test the debug option in the affected code to make sure the time change is not sent to the controler
        msclass._debugging = False
Beispiel #14
0
    def testchecktime(self):

        mdf = """DTMF>N027
The time is 12:23 P.M.
OK
DTMF"""
        cs = dlxii.Device()
        tup = cs.newcmd_dict['gtime']
        self.assertEqual('N027', tup[0])
        pat = tup[1]
        mx = pat.search(mdf)
        _res = tup[2](mx)
        sttpl = cs.newcmd_dict['stime']
        matchtime = time.strptime("03 Jan 2018 12 23 30", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertFalse(cd)

        matchtime = time.strptime("03 Jan 2018 11 30 30", "%d %b %Y %H %M %S")
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02511300', cd)

        matchtime = time.strptime("03 Jan 2018 00 30 30", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02512300', cd)

        matchtime = time.strptime("03 Feb 2018 13 30 30", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02501301', cd)

        matchtime = time.strptime("03 Jan 2018 23 30 30", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02511301', cd)

        mdf = """DTMF>N027
The time is 12:23 A.M.
OK
DTMF"""
        tup = cs.newcmd_dict['gtime']
        self.assertEqual('N027', tup[0])
        _res = tup[2](tup[1].search(mdf))
        sttpl = cs.newcmd_dict['stime']
        matchtime = time.strptime("03 Jan 2018 00 23 30", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertFalse(cd)

        matchtime = time.strptime("03 Jan 2018 11 30 30", "%d %b %Y %H %M %S")
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02511300', cd)

        matchtime = time.strptime("03 Jan 2018 11 30 30", "%d %b %Y %H %M %S")
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02511300', cd)

        mdf = """DTMF>N027
The time is 12:00 A.M.
OK
DTMF"""
        tup = cs.newcmd_dict['gtime']
        self.assertEqual('N027', tup[0])
        _res = tup[2](tup[1].search(mdf))
        sttpl = cs.newcmd_dict['stime']
        matchtime = time.strptime("03 Jan 2018 00 00 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertFalse(cd)

        matchtime = time.strptime("03 Jan 2018 00 01 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02512010', cd)

        matchtime = time.strptime("03 Jan 2018 23 59 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02511591', cd)

        mdf = """DTMF>N027
The time is 12:00 P.M.
OK
DTMF"""
        tup = cs.newcmd_dict['gtime']
        self.assertEqual('N027', tup[0])
        _res = tup[2](tup[1].search(mdf))
        sttpl = cs.newcmd_dict['stime']
        matchtime = time.strptime("03 Jan 2018 12 00 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertFalse(cd)

        matchtime = time.strptime("03 Jan 2018 12 01 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02512011', cd)

        matchtime = time.strptime("03 Jan 2018 11 59 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02511590', cd)

        mdf = """DTMF>N027
The time is 12:01 P.M.
OK
DTMF"""
        tup = cs.newcmd_dict['gtime']
        self.assertEqual('N027', tup[0])
        _res = tup[2](tup[1].search(mdf))
        sttpl = cs.newcmd_dict['stime']
        matchtime = time.strptime("03 Jan 2018 12 01 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertFalse(cd)

        matchtime = time.strptime("03 Jan 2018 12 00 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02512001', cd)

        matchtime = time.strptime("03 Jan 2018 11 59 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02511590', cd)

        mdf = """DTMF>N027
The time is 11:59 A.M.
OK
DTMF"""
        tup = cs.newcmd_dict['gtime']
        self.assertEqual('N027', tup[0])
        _res = tup[2](tup[1].search(mdf))
        sttpl = cs.newcmd_dict['stime']
        matchtime = time.strptime("03 Jan 2018 11 59 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertFalse(cd)
        matchtime = time.strptime("03 Jan 2018 12 00 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02512001', cd)
        matchtime = time.strptime("03 Jan 2018 11 58 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02511580', cd)

        mdf = """DTMF>N027
The time is 1:05 A.M.
OK
DTMF"""
        tup = cs.newcmd_dict['gtime']
        self.assertEqual('N027', tup[0])
        _res = tup[2](tup[1].search(mdf))
        sttpl = cs.newcmd_dict['stime']
        matchtime = time.strptime("03 Jan 2018 01 05 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertFalse(cd)
        matchtime = time.strptime("03 Jan 2018 00 00 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02512000', cd)
        matchtime = time.strptime("03 Jan 2018 01 58 00", "%d %b %Y %H %M %S")
        # time.localtime(time.time()))
        cd = updatetime.check_time(_res, sttpl, matchtime)
        self.assertEqual('N02501580', cd)
 def testfmtcmd(self):
     cs = dlxii.Device()
     tup = cs.newcmd_dict['sdate']
     arg = (tup[0], 'arg1', 'arg2', 'arg3', 'arg4')
     cmd = tup[3](arg)
     self.assertEqual('N028arg1arg2arg3arg4', cmd)
Beispiel #16
0
    def testfindBaud(self):
        """
        1) test that an open correct speed port is detected
        2) test that a closed correct speed port is detected
        3) test that a closed first attempt  for 9600 is ok
        4) test that a open second attemtp for 9600 is ok
        5) test that a first attempt at 19200 is ok
        6) test special case of msclass._dbidx = -1 is ok

        """

        sp = myserial.MySerial(dlxii.Device())
        msclass = myserial.MySerial
        TestMySerial.gsp = sp
        msclass._debugging = True

        # test 1) findBaudRate open, 9600
        msclass._dbidx = 0
        msclass._debugreturns = [
            b'preread ignored', b'9600 open default succeed DTMF>'
        ]

        sp.port = TestMySerial.sdevice
        sp.baudrate = 9600
        sp.timeout = 1.5
        sp.open()
        self.assertTrue(sp.find_baud_rate())
        self.assertEqual(9600, sp.baudrate)
        self.assertTrue(sp.isOpen())

        # test 2) findBaudRate close, 9600
        sp.close()
        msclass._dbidx = 0
        msclass._debugreturns = [
            b'preread ignored', b'9600 close default succeed DTMF>'
        ]
        self.assertTrue(sp.find_baud_rate())
        self.assertEqual(9600, sp.baudrate)
        self.assertFalse(sp.isOpen())

        # test 3) findBaudRate close bad baud, found 9600 baud
        msclass._dbidx = 0
        msclass._debugreturns = [
            b'preread ignored', b'any fail DMF>', b'preread ignored',
            b'9600 close first scan succeed DTMF>'
        ]

        self.assertTrue(sp.find_baud_rate())
        self.assertEqual(9600, sp.baudrate)
        self.assertFalse(sp.isOpen())

        # test 4) findBaudRate open bad baud, found 9600 baud
        msclass._dbidx = 0
        msclass._debugreturns = [
            b'preread ignored', b'kjljjglkjerrl', b'preread ignored',
            b'kjljjglkjerrl', b'preread ignored',
            b'9600 open second scan succeed DTMF>'
        ]
        sp.open()
        self.assertTrue(sp.find_baud_rate())
        self.assertEqual(9600, sp.baudrate)
        self.assertTrue(sp.isOpen())

        # test 5) test that a first attempt at 19200 is ok
        msclass._dbidx = 0
        msclass._debugreturns = [
            b'preread ignored', b'9600 fail try 1 MF>', b'preread ignored',
            b'9600 fail try 2 MF>', b'preread ignored',
            b'19200 fail try 1 TMF>', b'preread ignored',
            b'19200 succeed try 2 DTMF>'
        ]
        self.assertTrue(sp.find_baud_rate())
        self.assertEqual(19200, sp.baudrate)
        self.assertTrue(sp.isOpen())

        # test 6) check that dbidx = -1 does as expected
        msclass._dbidx = -1
        self.assertEqual(b'OK\nDTMF>', sp.dread(99)[0])

        msclass._dbidx = 0
        sp.close()
    def testnewcmd_dict(self):
        cs = dlxii.Device()
        mdf = """DTMF>N054 501N054501
Macro 501 contains 2 commands:
  #00  Command #038 with 00 digits of data:
  #01  Command #000 with 02 digits of data: 13
This macro is 9 percent full
OK
OK
DTMF>"""
        tup = cs.newcmd_dict['rmc']
        self.assertEqual('N054', tup[0])
        pat = tup[1]
        mx = pat.search(mdf)
        res = mx.groupdict()
        self.assertEqual('2', res['numins'])
        self.assertEqual('9', res['full'])
        self.assertEqual('501', res['macro'])
        cmdraw = res['cmds'].strip()
        cmdlines = [l for l in cmdraw.split('\n') if l.strip()]
        self.assertEqual(2, len(cmdlines))
        self.assertTrue('#038' in cmdlines[0])
        self.assertTrue('#000' in cmdlines[1])

        mx = pat.search(mdf)
        res = tup[2](mx)
        self.assertEqual('2', res['numins'])
        self.assertEqual('9', res['full'])
        self.assertEqual('501', res['macro'])
        self.assertEqual(2, len(res['cmds']))
        cmdlines = res['cmds']
        self.assertTrue('#038' in cmdlines[0])
        self.assertTrue('#000' in cmdlines[1])

        mdf = """OK
DTMF>N011 521N011521
Command number 521 is named C47571.  It takes 0 digits of data.
OK
OK
DTMF>"""
        tup = cs.newcmd_dict['rcn']
        self.assertEqual('N011', tup[0])
        pat = tup[1]
        mx = pat.search(mdf)
        res = tup[2](mx)
        self.assertEqual('521', res['cmdno'])
        self.assertEqual('C47571', res['name'])
        self.assertEqual('0', res['digs'])

        mdf = """DTMF>N029
This is Wednesday, 01-03-2018
OK
DTMF>"""
        tup = cs.newcmd_dict['gdate']
        self.assertEqual('N029', tup[0])
        pat = tup[1]
        mx = pat.search(mdf)
        res = tup[2](mx)
        self.assertEqual('Wednesday', res['A'])
        self.assertEqual('01', res['m'])
        self.assertEqual('03', res['d'])
        self.assertEqual('2018', res['Y'])

        mdf = """DTMF>N027
The time is 12:23 P.M.
OK
DTMF"""
        tup = cs.newcmd_dict['gtime']
        self.assertEqual('N027', tup[0])
        pat = tup[1]
        mx = pat.search(mdf)
        res = tup[2](mx)
        self.assertEqual('12', res['I'])
        self.assertEqual('23', res['M'])
        self.assertEqual('P.M.', res['p'])