Esempio n. 1
0
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
Esempio n. 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
Esempio n. 3
0
 def testNoName(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     self.assertIsNone(employees.getByName('badname'))
Esempio n. 4
0
 def testTurnoverByName(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getByName('frank')
     self.assertEqual(turnover, 100000 + 140000 + 200000)
Esempio n. 5
0
 def testNoName(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     self.assertIsNone(employees.getByName('badname'))
Esempio n. 6
0
 def testTurnoverByName(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getByName('frank')
     self.assertEqual(turnover, 100000 + 140000 + 200000)
Esempio n. 7
0
def main(argv=sys.argv):

    """ Test employees class.
    :param argv:
    """

    __version__ = Employees.__version__

    parser = argparse.ArgumentParser(
        prog=os.path.basename(argv[0]),
        usage='%(prog)s [options] infile',
        description='a Python example program to show YAML processing',
        epilog='© 2014 Frank H Jung mailto:[email protected]')
    parser.add_argument(
        'infile',
        nargs='?',
        type=argparse.FileType('r'),
        default='test/test.yaml',
        help='alternate YAML 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 YAML
    e = Employees(infile)

    logger.debug("infile ......................: {}".format(infile.name))
    logger.debug("prog ........................: {}".format(prog))
    logger.debug("verbose .....................: {}".format(verbose))
    logger.debug("employees ...................:")
    for n, t in e.employees.items():
        logger.debug("\t{0}\t{1}".format(n, t))

    t = e.getName(3)
    logger.debug("name for id 3 ...............: {}".format(t))

    t = e.getById(3)
    logger.debug("turnover for 3 ..............: ${:,}".format(t))

    t = e.getByName('frank')
    logger.debug("turnover for frank ..........: ${:,}".format(t))

    t = e.getByYear(2012)
    logger.debug("turnover for 2012 ...........: ${:,}".format(t))

    t = list(e.listById(3))
    logger.debug("list turnover by id .........: {}".format(t))

    t = list(e.listByName('frank'))
    logger.debug("list turnover by name .......: {}".format(t))

    t = list(e.listByYear(2013))
    logger.debug("list turnover by year .......: {}".format(t))

    return 0