예제 #1
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))
예제 #2
0
 def test_by_year(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees)
     self.assertEqual(100000, employees.get_by_year(2011))
     self.assertEqual(270000, employees.get_by_year(2012))
     self.assertEqual(420000, employees.get_by_year(2013))
     self.assertEqual(210000, employees.get_by_year(2014))
예제 #3
0
def main():

    # initialize queue
    q = queue.Queue()

    # initialize employees pool
    employees = []

    # Create employees pool
    # keep job status and available hours
    employees.append(Employees(True, 2))
    employees.append(Employees(True, 3))
    employees.append(Employees(True, 4))
    employees.append(Employees(True, 5))
    employees.append(Employees(True, 6))

    sorted_order_employees_pool = sorted(employees, reverse=True)

    # tread start
    worker_tread = threading.Thread(target=worker,
                                    args=(q, sorted_order_employees_pool))
    worker_tread.setDaemon(True)
    worker_tread.start()

    # assigned job
    q.put(Jobs(False, 5))
    q.put(Jobs(False, 20))
    q.put(Jobs(False, 1))
    q.put(Jobs(False, 3))

    q.join()

    print("all work is done")
예제 #4
0
 def test_list_by_year(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees)
     turnover = list(employees.list_by_year(2013))
     self.assertEqual(2, len(turnover))
     self.assertIn(200000, turnover)
     self.assertIn(220000, turnover)
     self.assertNotIn(2013, turnover)
예제 #5
0
 def test_list_by_name(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees)
     turnovers = list(employees.list_by_name('frank'))
     self.assertEqual(3, len(turnovers))
     self.assertIn(100000, turnovers)
     self.assertIn(140000, turnovers)
     self.assertIn(200000, turnovers)
     self.assertNotIn(220000, turnovers)
예제 #6
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
예제 #7
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
예제 #8
0
 def test_for_name_by_year(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees)
     self.assertEqual(
         100000, employees.get_for_name_by_year(name='frank', year=2011))
     self.assertEqual(
         140000, employees.get_for_name_by_year(name='frank', year=2012))
     self.assertEqual(
         200000, employees.get_for_name_by_year(name='frank', year=2013))
     self.assertEqual(130000,
                      employees.get_for_name_by_year(name='jo', year=2012))
     self.assertEqual(220000,
                      employees.get_for_name_by_year(name='jo', year=2013))
     self.assertEqual(210000,
                      employees.get_for_name_by_year(name='jo', year=2014))
예제 #9
0
 def test_bad_for_name_by_year(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees)
     self.assertIsNone(employees.get_for_name_by_year('frank', 1999))
     self.assertIsNone(employees.get_for_name_by_year('jo', 1999))
     self.assertIsNone(employees.get_for_name_by_year('badname', 2011))
     self.assertIsNone(employees.get_for_name_by_year('badname', 2012))
     self.assertIsNone(employees.get_for_name_by_year('badname', 2013))
     self.assertIsNone(employees.get_for_name_by_year('badname', 2014))
예제 #10
0
 def testNoName(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     self.assertIsNone(employees.getByName('badname'))
예제 #11
0
 def test_load_by_file(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees)
예제 #12
0
 def testId(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getById('003')
     self.assertIsNotNone(turnover, "expected employee with ID 003")
     self.assertEqual(turnover, 100000 + 140000 + 200000)
예제 #13
0
 def testTurnoverByName(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getByName('frank')
     self.assertEqual(turnover, 100000 + 140000 + 200000)
예제 #14
0
 def testLoadFromFile2(self):
     employees = Employees()
     employees.loadFromFile(file(self.TEST_FILE))
     self.assertIsNotNone(employees, 'expected employees')
예제 #15
0
 def testTurnoverTotalByYear(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getTotalByYear(2012)
     self.assertEqual(turnover, 270000)
예제 #16
0
 def testTurnoverByYear(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getByYear('frank', 2012)
     self.assertEqual(turnover, 140000)
예제 #17
0
 def test_bad_list_by_id(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees)
     self.assertIsNone(employees.list_by_id(1))
예제 #18
0
 def test_bad_list_by_name(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees)
     self.assertIsNone(employees.list_by_name('badname'))
예제 #19
0
 def test_by_name(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees)
     self.assertEqual(440000, employees.get_by_name('frank'))
     self.assertEqual(560000, employees.get_by_name('jo'))
예제 #20
0
 def test_name(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees)
     self.assertEqual('frank', employees.get_name(3))
     self.assertEqual('jo', employees.get_name(4))
예제 #21
0
 def test_dump(self):
     employees = Employees(self.TEST_FILE)
     dump = employees.dump()
     self.assertIn('frank:', dump)
     self.assertIn('jo:', dump)
예제 #22
0
 def testTurnoverById(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getById('004')
     self.assertEqual(turnover, 130000 + 220000 + 210000)
예제 #23
0
 def test_bad_by_year(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees)
     self.assertEqual(0, employees.get_by_year(1999))
예제 #24
0
 def testNoId(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     self.assertIsNone(employees.getById(001))
예제 #25
0
 def testTurnoverByYear(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getByYear('frank', 2012)
     self.assertEqual(turnover, 140000)
예제 #26
0
 def testNoYear(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getByYear('frank', 2001)
     self.assertIsNone(turnover)
예제 #27
0
 def testTurnoverTotalByYear(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getTotalByYear(2012)
     self.assertEqual(turnover, 270000)
예제 #28
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")
예제 #29
0
        version='%(prog)s {version}'.format(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 ......................: %s", INFILE.name)
    LOGGER.debug("prog ........................: %s", PROG)
    LOGGER.debug("verbose .....................: %s", VERBOSE)
    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)
예제 #30
0
 def test_bad_id(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees)
     self.assertIsNone(employees.get_name(1))
예제 #31
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))
예제 #32
0
 def testNoName(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     self.assertIsNone(employees.getByName('badname'))
예제 #33
0
 def testTurnoverByName(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getByName('frank')
     self.assertEqual(turnover, 100000 + 140000 + 200000)
예제 #34
0
 def testNoId(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     self.assertIsNone(employees.getById(001))
예제 #35
0
 def test_bad_list_by_year(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees)
     self.assertIsNone(employees.list_by_year(1999))
예제 #36
0
 def testNoYear(self):
     employees = Employees(self.TEST_FILE)
     self.assertIsNotNone(employees, 'expected employees')
     turnover = employees.getByYear('frank', 2001)
     self.assertIsNone(turnover)
예제 #37
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
예제 #38
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")
예제 #39
0
 def testLoadFromFile2(self):
     employees = Employees()
     employees.loadFromFile(file(self.TEST_FILE))
     self.assertIsNotNone(employees, 'expected employees')