def testDump(self): employees = Employees(self.TEST_FILE) dump = employees.dump() count = len(dump.split('\n')) self.assertEqual( count, 17, "expected %i lines dump, got %i" % (17, count))
def main(argv=sys.argv): """ Test employees class. """ __version__ = '0.3.0' parser = argparse.ArgumentParser( prog=os.path.basename(argv[0]), usage='%(prog)s [options]', description='a Python example program to show XML processing', epilog='© 2013-2018 Frank H Jung mailto:[email protected]') parser.add_argument( 'infile', nargs='?', type=argparse.FileType('r'), default='data/test.xml', help='alternate XML file to test') parser.add_argument( '-v', '--verbose', help='verbose output', action='count') parser.add_argument( '--version', action='version', version=__version__) # process command line arguments args = parser.parse_args() prog = parser.prog infile = args.infile verbose = args.verbose # show command parameters logging.basicConfig(format="%(asctime)s %(message)s", level=logging.INFO) logger = logging.getLogger(__name__) if verbose: logger.setLevel(logging.DEBUG) # load employees from XML e = Employees(infile) logger.debug("infile ......................: {}".format(infile.name)) logger.debug("prog ........................: {}".format(prog)) logger.debug("verbose .....................: {}".format(verbose)) logger.debug("dump ........................: \n{}".format(e.dump())) t = e.getById('003') logger.debug("total for id 3 ..............: {}".format(t)) t = e.getByName('frank') logger.debug("total for frank .............: ${:,}".format(t)) t = e.getTotalByYear(2012) logger.debug("turnover for 2012 ...........: ${:,}".format(t)) t = e.getByYear('frank', 2012) logger.debug("turnover for frank in 2012 ..: {}".format(t)) return 0
def main(argv=sys.argv): """ Test employees class. """ __version__ = '0.1.0' parser = argparse.ArgumentParser( prog=os.path.basename(argv[0]), usage='%(prog)s [options]', description='a Python example program to show XML processing', epilog='© 2014 Frank H Jung mailto:[email protected]') parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default='data/test.xml', help='alternate XML file to test') parser.add_argument('-v', '--verbose', help='verbose output', action='count') parser.add_argument('--version', action='version', version=__version__) # process command line arguments args = parser.parse_args() prog = parser.prog infile = args.infile verbose = args.verbose # show command parameters logging.basicConfig(format="%(asctime)s %(message)s", level=logging.INFO) logger = logging.getLogger(__name__) if verbose: logger.setLevel(logging.DEBUG) # load employees from XML e = Employees(infile) logger.debug("infile ......................: {}".format(infile.name)) logger.debug("prog ........................: {}".format(prog)) logger.debug("verbose .....................: {}".format(verbose)) logger.debug("dump ........................: \n{}".format(e.dump())) t = e.getById(3) logger.debug("name for id 3 ...............: {}".format(t)) t = e.getByName('frank') logger.debug("turnover for frank ..........: ${:,}".format(t)) t = e.getByYear(2012, 'frank') logger.debug("turnover for frank in 2012 ..: {}".format(t)) t = e.getTotalByYear(2012) logger.debug("turnover for 2012 ...........: ${:,}".format(t)) return 0
def testDump(self): employees = Employees(self.TEST_FILE) dump = employees.dump() count = len(dump.split('\n')) self.assertEqual(count, 17, "expected %i lines dump, got %i" % (17, count))
def test_dump(self): employees = Employees(self.TEST_FILE) dump = employees.dump() self.assertIn('frank:', dump) self.assertIn('jo:', dump)
LOGGER.debug("version .....................: %s", __version__) LOGGER.debug("employees ...................:") for n, t in E.employees.items(): LOGGER.debug("\t%s\t%s", n, t) T = E.get_name(3) LOGGER.debug("name for id 3 ...............: %s", T) T = E.get_by_id(3) LOGGER.debug("turnover for 3 ..............: %i", T) T = E.get_by_name('frank') LOGGER.debug("turnover for frank ..........: %i", T) T = E.get_by_year(2012) LOGGER.debug("turnover for 2012 ...........: %i", T) T = list(E.list_by_id(3)) LOGGER.debug("list turnover by id .........: %s", T) T = list(E.list_by_name('frank')) LOGGER.debug("list turnover by name .......: %s", T) T = list(E.list_by_year(2013)) LOGGER.debug("list turnover by year .......: %s", T) if VERBOSE: print(E.dump()) sys.exit(0)