コード例 #1
0
ファイル: main.py プロジェクト: frankhjung/python-xml
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
コード例 #2
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
コード例 #3
0
 def testZeroTurnover(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     self.assertEqual(
         employees.getTotalByYear(2001), None,
         "expected no turnover for this year")
コード例 #4
0
 def testTurnoverTotalByYear(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getTotalByYear(2012)
     self.assertEqual(turnover, 270000)
コード例 #5
0
 def testZeroTurnover(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     self.assertEqual(employees.getTotalByYear(2001), None,
                      "expected no turnover for this year")
コード例 #6
0
 def testTurnoverTotalByYear(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getTotalByYear(2012)
     self.assertEqual(turnover, 270000)