def test_long_job (self): s = Session() job = Job("res1.1") job.start = datetime(2000, 1, 1) job.end = datetime(2000, 2, 1) s.add(job) stdout, stderr = capture(lambda: print_jobs_list([job])) assert_equal_multiline(stdout.getvalue(), dedent("""\ res1.1 744:00:00 0.0 """)) assert_equal_multiline(stderr.getvalue(), dedent("""\ ID Name User Account Duration Charged ------------------- ---------- -------- --------------- --------- ------------- --------- ------------- 744:00:00 0.0 Units are undefined. """))
def test_full_jobs (self): s = Session() project1 = Project("1") project2 = Project("2") user1 = User("1") user2 = User("2") res1 = Resource("1") a = Allocation(project1, res1, 0, datetime(2000, 1, 1), datetime(2001, 1, 1)) j1 = Job("res1.1") j2 = Job("res1.2") j3 = Job("res1.3") j2.user = user1 j3.user = user2 j1.account = project1 j3.account = project2 j1.name = "somename" j1.charges = [Charge(a, 10), Charge(a, 20)] j1.charges[1].refund(5) j1.start = datetime(2000, 1, 1) j2.start = datetime(2000, 1, 2) j1.end = j1.start + timedelta(minutes=30) for job in [j1, j2, j3]: s.add(job) stdout, stderr = capture(lambda: print_jobs_list([j1, j2, j3])) assert_equal_multiline(stdout.getvalue(), dedent("""\ res1.1 somename project1 0:30:00 25.0 res1.2 user1 0.0 res1.3 user2 project2 0.0 """)) assert_equal_multiline(stderr.getvalue(), dedent("""\ ID Name User Account Duration Charged ------------------- ---------- -------- --------------- --------- ------------- --------- ------------- 0:30:00 25.0 Units are undefined. """))
def test_job (self): user1 = User.fetch("user1") project1 = Project.fetch("project1") res1 = Resource.fetch("res1") allocation1 = Allocation(project1, res1, 0, datetime(2000, 1, 1), datetime(2001, 1, 1)) charges = [Charge(allocation1, 0), Charge(allocation1, 0)] job = Job("www.example.com.123") job.user = user1 job.group = "agroup" job.account = project1 job.name = "myjob" job.queue = "aqueue" job.reservation_name = "areservation" job.reservation_id = "www.example.com.1" job.ctime = datetime(2000, 1, 1) job.qtime = datetime(2001, 1, 1) job.etime = datetime(2001, 1, 2) job.start = datetime(2001, 2, 2) job.exec_host = "ANL-R00-M1-512" job.resource_list = {'nodes':64, 'walltime':timedelta(minutes=10), 'otherresource':"stringvalue"} job.session = 123 job.alternate_id = "anotherid" job.end = datetime(2001, 2, 3) job.exit_status = 128 job.resources_used = {'nodes':64, 'walltime':timedelta(minutes=10), 'otherresource':"stringvalue"} job.accounting_id = "someaccountingid" job.charges = charges Session.add(job) Session.flush() stdout, stderr = capture(lambda: print_jobs([job])) assert_equal_multiline(stdout.getvalue(), dedent("""\ Job www.example.com.123 * User: user1 * Group: agroup * Account: project1 * Name: myjob * Queue: aqueue * Reservation name: areservation * Reservation id: www.example.com.1 * Creation time: 2000-01-01 00:00:00 * Queue time: 2001-01-01 00:00:00 * Eligible time: 2001-01-02 00:00:00 * Start: 2001-02-02 00:00:00 * Execution host: ANL-R00-M1-512 * Resource list: * nodes: 64 * otherresource: stringvalue * walltime: 0:10:00 * Session: 123 * Alternate id: anotherid * End: 2001-02-03 00:00:00 * Exit status: 128 * Resources used: * nodes: 64 * otherresource: stringvalue * walltime: 0:10:00 * Accounting id: someaccountingid """))