Ejemplo n.º 1
0
def test_renderer_init(renderer):
    assert renderer.formatters == [
        output_renderer.Column_Formatter('JobID%>'),
        output_renderer.Column_Formatter('State'),
        output_renderer.Column_Formatter('Elapsed%>'),
        output_renderer.Column_Formatter('CPUEff'),
        output_renderer.Column_Formatter('MemEff'),
    ]
    assert sorted(renderer.query_columns) == sorted(
        ('JobID JobIDRaw State Elapsed TotalCPU AllocCPUS REQMEM '
         'NNodes MaxRSS').split())

    renderer = output_renderer.Output_Renderer(min_required, '')
    assert renderer.formatters == []
    assert sorted(renderer.query_columns) == sorted(
        ('JobID JobIDRaw State').split())

    renderer = output_renderer.Output_Renderer(min_required, 'TotalCPU%<5')
    assert renderer.formatters == [
        output_renderer.Column_Formatter('TotalCPU%<5'),
    ]
    assert sorted(renderer.query_columns) == sorted(
        ('JobID JobIDRaw State TotalCPU').split())
Ejemplo n.º 2
0
def test_format_jobs_single_str(some_jobs):
    renderer = output_renderer.Output_Renderer(min_required, 'JobID%>')
    assert len(renderer.formatters) == 1
    assert renderer.formatters[0].alignment == '>'

    result = renderer.format_jobs(some_jobs).split('\n')

    # alignment is switched
    assert renderer.formatters[0].alignment == '<'
    assert result == [
        '24371655',
        '24371656',
        '24371657',
        '24371658',
        '24371659',
        '24371660',
    ]
Ejemplo n.º 3
0
def test_renderer_format_jobs(some_jobs):
    renderer = output_renderer.Output_Renderer(
        min_required, 'JobID,State,Elapsed,CPUEff,REQMEM,TimeEff')
    result = renderer.format_jobs(some_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()
Ejemplo n.º 4
0
def test_format_jobs_empty(some_jobs):
    renderer = output_renderer.Output_Renderer(min_required, '')
    result = renderer.format_jobs(some_jobs)
    assert result == ''
Ejemplo n.º 5
0
def renderer():
    # default renderer with valid names for only default string
    return output_renderer.Output_Renderer(min_required)
Ejemplo n.º 6
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()