Example #1
0
    def test0(self):
        displayNextTest(self)

        appRoutines.unitTestMode = True
        testutils_files.testx()
        with LogCapture() as cap:

            log.init_LogCapture()
            f = testutils_files.openCSVFile(self.fileRef)
            self.f = f
            self.assertIs(type(f), file,'open() function must return file object when file exists.')

            fd = csv.DictReader(f)
            print('- Column Headers:  %s' % fd.fieldnames)   # list of column header strings
            cap.clear()    # ignore previous logs
            self.assertTrue( set(parmTable.requiredColumnNames).issubset(fd.fieldnames),
                                msg='Required columns names missing.')
            row = next(fd)
            crow = parmTable.parmFileRec(row)
            print('row = %d  ID = "%s"' % (0, crow.id))
            #self.assertEqual(crow.url, row['ID'],msg='dict lookup and parmFileRec object agree on value')
            # same as assertEqual except displays the compared values on failure
            compare(crow.id, row['ID'],msg='dict lookup and parmFileRec object agree on value')

            print('Number of missing columns = %d  ' % crow.missingColumnsCnt)
            self.assertEqual('1', crow.id, msg='ID column does not contain correct value')
            print(cap)
            cap.check()    # no logs expected
Example #2
0
 def test1_open(self):
     displayNextTest(self)
     with LogCapture() as cap:
         log.init_LogCapture()
         f = openFile.openFile(self.fileRefBad)
         print("File object <-- open non-existant-file:    %s" % type(f))
         print(cap)
         compare(cap.records[0].getMessage(),openFile.msg_CSVFileNotFound)
         self.assertIsNone(f,'Function must return None for this non-existent file.')
Example #3
0
 def test2_openFileRef(self):
     displayNextTest(self)
     with LogCapture() as cap:
         log.init_LogCapture()
         f = openFile.openFile(self.fileRef)
             # print("File object:    %s" % type(f))
             # if isinstance(f,file):
             #     print('is file type')
         print(cap)
         self.assertIsInstance(f, file,'assertIsInstance file .')
         self.assertIs(type(f), file,'open() function must return file object when file exists.')
         #cap.check((log.techlName, 'INFO', self.msg1))     # a unittest assert
         f.close()
Example #4
0
 def common(cls):
     apptestutils.displayNextTest(cls)
     log.init_LogCapture()       # start logging for unit testing
     appData.runMode = appData.RUNMODE_TEST