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_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))
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")
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)
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)
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 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))
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))
def testNoName(self): employees = Employees(self.TEST_FILE) self.assertIsNotNone(employees, 'expected employees') self.assertIsNone(employees.getByName('badname'))
def test_load_by_file(self): employees = Employees(self.TEST_FILE) self.assertIsNotNone(employees)
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)
def testTurnoverByName(self): employees = Employees(self.TEST_FILE) self.assertIsNotNone(employees, 'expected employees') turnover = employees.getByName('frank') self.assertEqual(turnover, 100000 + 140000 + 200000)
def testLoadFromFile2(self): employees = Employees() employees.loadFromFile(file(self.TEST_FILE)) self.assertIsNotNone(employees, 'expected employees')
def testTurnoverTotalByYear(self): employees = Employees(self.TEST_FILE) self.assertIsNotNone(employees, 'expected employees') turnover = employees.getTotalByYear(2012) self.assertEqual(turnover, 270000)
def testTurnoverByYear(self): employees = Employees(self.TEST_FILE) self.assertIsNotNone(employees, 'expected employees') turnover = employees.getByYear('frank', 2012) self.assertEqual(turnover, 140000)
def test_bad_list_by_id(self): employees = Employees(self.TEST_FILE) self.assertIsNotNone(employees) self.assertIsNone(employees.list_by_id(1))
def test_bad_list_by_name(self): employees = Employees(self.TEST_FILE) self.assertIsNotNone(employees) self.assertIsNone(employees.list_by_name('badname'))
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'))
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))
def test_dump(self): employees = Employees(self.TEST_FILE) dump = employees.dump() self.assertIn('frank:', dump) self.assertIn('jo:', dump)
def testTurnoverById(self): employees = Employees(self.TEST_FILE) self.assertIsNotNone(employees, 'expected employees') turnover = employees.getById('004') self.assertEqual(turnover, 130000 + 220000 + 210000)
def test_bad_by_year(self): employees = Employees(self.TEST_FILE) self.assertIsNotNone(employees) self.assertEqual(0, employees.get_by_year(1999))
def testNoId(self): employees = Employees(self.TEST_FILE) self.assertIsNotNone(employees, 'expected employees') self.assertIsNone(employees.getById(001))
def testNoYear(self): employees = Employees(self.TEST_FILE) self.assertIsNotNone(employees, 'expected employees') turnover = employees.getByYear('frank', 2001) self.assertIsNone(turnover)
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")
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)
def test_bad_id(self): employees = Employees(self.TEST_FILE) self.assertIsNotNone(employees) self.assertIsNone(employees.get_name(1))
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_bad_list_by_year(self): employees = Employees(self.TEST_FILE) self.assertIsNotNone(employees) self.assertIsNone(employees.list_by_year(1999))
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
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")