Esempio n. 1
0
def test_eq():
    job1 = job_module.Job('j1', 'j1', 'filename')
    job2 = job_module.Job('j1', 'j1', 'filename')
    assert job1 == job2

    job2 = job_module.Job('j2', 'j1', 'filename')
    assert job1 != job2
    job2 = dict()
    assert job1 != job2
Esempio n. 2
0
def test_get_entry(job):
    job.state = 'TEST'
    assert job.get_entry('JobID') == 'filename'
    assert job.get_entry('State') == 'TEST'
    assert job.get_entry('MemEff') == '---'
    assert job.get_entry('TimeEff') == '---'
    assert job.get_entry('CPUEff') == '---'
    assert job.get_entry('undefined') == '---'

    job = job_module.Job('24371655', '24371655', None)
    job.update({
        'JobID': '24371655',
        'State': 'CANCELLED',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:00:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    assert job.get_entry('JobID') == '24371655'
    assert job.get_entry('State') == 'CANCELLED'
    assert job.get_entry('MemEff') == 0.0
    assert job.get_entry('TimeEff') == 0.0
    assert job.get_entry('CPUEff') == '---'
    assert job.get_entry('undefined') == '---'
    assert job.get_entry('Elapsed') == '00:00:00'
def test_formatter_compute_width():
    fmt = output_renderer.Column_Formatter('JobID')
    # matches title
    jobs = [
        job_module.Job(None, 'tes', None),
        job_module.Job(None, 'tin', None),
        job_module.Job(None, 'g', None),
    ]
    fmt.compute_width(jobs)
    assert fmt.width == 7

    # already set
    jobs = [
        job_module.Job(None, 'aLongEntry', None),
        job_module.Job(None, 'addAnother', None),
    ]
    fmt.compute_width(jobs)
    assert fmt.width == 7

    fmt = output_renderer.Column_Formatter('JobID')
    fmt.compute_width(jobs)
    assert fmt.width == 12
Esempio n. 4
0
def test_parse_bug():
    job = job_module.Job('24371655', '24371655', None)
    job.update({
        'AllocCPUS': '1',
        'Elapsed': '00:00:19',
        'JobID': '34853801.extern',
        'JobIDRaw': '34853801.extern',
        'JobName': 'extern',
        'MaxRSS': '0',
        'NNodes': '1',
        'REQMEM': '4Gn',
        'State': 'COMPLETED',
        'Timelimit': '',
        'TotalCPU': '00:00:00',
    })
Esempio n. 5
0
def test_update_part_job():
    job = job_module.Job('24371655', '24371655', None)
    job.update({
        'JobID': '24371655.batch',
        'State': 'COMPLETED',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:10:00',
        'MaxRSS': '495644K',
        'NNodes': '1',
        'NTasks': ''
    })
    assert job.state is None
    assert job.time == '---'
    assert job.cpu == '---'
    assert job.totalmem is None
    assert job.stepmem == 495644
Esempio n. 6
0
def job():
    return job_module.Job('job', 'jobid', 'filename')
Esempio n. 7
0
def test_update_main_job():
    job = job_module.Job('24371655', '24371655', None)
    job.update({
        'JobID': '24371655',
        'State': 'COMPLETED',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:10:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    assert job.state == 'COMPLETED'
    assert job.time == '00:10:00'
    assert job.time_eff == 50.0
    assert job.cpu == 90.0
    assert job.totalmem == 1 * 1024**2

    job = job_module.Job('24371655', '24371655', None)
    job.update({
        'JobID': '24371655',
        'State': 'PENDING',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:10:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    assert job.state == 'PENDING'
    assert job.time == '---'
    assert job.time_eff == '---'
    assert job.cpu == '---'
    assert job.totalmem is None

    job = job_module.Job('24371655', '24371655', None)
    job.update({
        'JobID': '24371655',
        'State': 'RUNNING',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:10:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    assert job.state == 'RUNNING'
    assert job.time == '00:10:00'
    assert job.time_eff == 50.0
    assert job.cpu == '---'
    assert job.totalmem is None

    job = job_module.Job('24371655', '24371655', None)
    job.update({
        'JobID': '24371655',
        'State': 'CANCELLED',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:00:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    assert job.state == 'CANCELLED'
    assert job.time == '00:00:00'
    assert job.time_eff == 0.0
    assert job.cpu is None
    assert job.totalmem == 1024**2
Esempio n. 8
0
def test_repr():
    job1 = job_module.Job('j1', 'jid1', 'filename')
    assert repr(job1) == 'Job(job=j1, jobid=jid1, filename=filename)'

    job2 = job_module.Job('j2', 'jid2', None)
    assert repr(job2) == 'Job(job=j2, jobid=jid2, filename=None)'
Esempio n. 9
0
def test_name(job):
    assert job.name() == 'filename'
    job = job_module.Job('job', 'jobid', None)
    assert job.name() == 'jobid'
Esempio n. 10
0
def some_jobs():
    '''a few test jobs for generating an output table'''
    jobs = []
    job = job_module.Job('24371655', '24371655', None)
    job.update({
        'JobID': '24371655',
        'State': 'COMPLETED',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:10:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    jobs.append(job)
    job = job_module.Job('24371656', '24371656', None)
    job.update({
        'JobID': '24371656',
        'State': 'PENDING',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:10:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    jobs.append(job)
    job = job_module.Job('24371657', '24371657', None)
    job.update({
        'JobID': '24371657',
        'State': 'RUNNING',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:10:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    jobs.append(job)
    job = job_module.Job('24371658', '24371658', None)
    job.update({
        'JobID': '24371658',
        'State': 'CANCELLED',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:00:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    jobs.append(job)
    job = job_module.Job('24371659', '24371659', None)
    job.update({
        'JobID': '24371659',
        'State': 'TIMEOUT',
        'AllocCPUS': '1',
        'REQMEM': '2Gn',
        'TotalCPU': '00:04:00',
        'Elapsed': '00:21:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    jobs.append(job)
    job = job_module.Job('24371660', '24371660', None)
    job.update({
        'JobID': '24371660',
        'State': 'OTHER',
        'AllocCPUS': '1',
        'REQMEM': '2Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:12:05',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    jobs.append(job)
    return jobs
Esempio n. 11
0
def test_renderer_format_jobs():
    renderer = output_renderer.Output_Renderer(
        min_required, 'JobID,State,Elapsed,CPUEff,REQMEM,TimeEff')
    jobs = []
    job = job_module.Job('24371655', '24371655', None)
    job.update({
        'JobID': '24371655',
        'State': 'COMPLETED',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:10:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    jobs.append(job)
    job = job_module.Job('24371656', '24371656', None)
    job.update({
        'JobID': '24371656',
        'State': 'PENDING',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:10:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    jobs.append(job)
    job = job_module.Job('24371657', '24371657', None)
    job.update({
        'JobID': '24371657',
        'State': 'RUNNING',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:10:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    jobs.append(job)
    job = job_module.Job('24371658', '24371658', None)
    job.update({
        'JobID': '24371658',
        'State': 'CANCELLED',
        'AllocCPUS': '1',
        'REQMEM': '1Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:00:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    jobs.append(job)
    job = job_module.Job('24371659', '24371659', None)
    job.update({
        'JobID': '24371659',
        'State': 'TIMEOUT',
        'AllocCPUS': '1',
        'REQMEM': '2Gn',
        'TotalCPU': '00:04:00',
        'Elapsed': '00:21:00',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    jobs.append(job)
    job = job_module.Job('24371660', '24371660', None)
    job.update({
        'JobID': '24371660',
        'State': 'OTHER',
        'AllocCPUS': '1',
        'REQMEM': '2Gn',
        'TotalCPU': '00:09:00',
        'Elapsed': '00:12:05',
        'Timelimit': '00:20:00',
        'MaxRSS': '',
        'NNodes': '1',
        'NTasks': ''
    })
    jobs.append(job)
    result = renderer.format_jobs(jobs)
    ansi_escape = re.compile(r'\x1B[@-_][0-?]*[ -/]*[@-~]')
    # check removed codes
    codes = ansi_escape.findall(result)
    for i, c in enumerate(codes):
        print(f'{i} -> {repr(c)}')
    for code in codes[1::2]:  # normal
        assert code == '\x1b[0m'
    for code in codes[0:10:20]:
        assert code == '\x1b[1m'  # bold
    for i in (22, 24, 26, 28):
        assert codes[i] == '\x1b[31m'  # red
    for i in (12, 14, 30):
        assert codes[i] == '\x1b[32m'  # green
    for i in (20, ):
        assert codes[i] == '\x1b[33m'  # yellow
    for i in (16, ):
        assert codes[i] == '\x1b[34m'  # blue
    for i in (18, ):
        assert codes[i] == '\x1b[36m'  # cyan
    # remove color codes
    result = ansi_escape.sub('', result)
    lines = result.split('\n')
    assert lines[0].split() == \
        'JobID State Elapsed CPUEff REQMEM TimeEff'.split()
    assert lines[1].split() == \
        '24371655 COMPLETED 00:10:00 90.0% 1Gn 50.0%'.split()
    assert lines[2].split() == \
        '24371656 PENDING --- --- --- ---'.split()
    assert lines[3].split() == \
        '24371657 RUNNING 00:10:00 --- 1Gn 50.0%'.split()
    assert lines[4].split() == \
        '24371658 CANCELLED 00:00:00 --- 1Gn 0.0%'.split()
    assert lines[5].split() == \
        '24371659 TIMEOUT 00:21:00 19.0% 2Gn 105.0%'.split()
    assert lines[6].split() == \
        '24371660 OTHER 00:12:05 74.5% 2Gn 60.4%'.split()