Beispiel #1
0
def test_workrpt_order(tmpdir, fx_wrprep):
    """
    Times or dates out of order should produce SystemExit exception
    """
    pytest.debug_func()
    xyz = tmpdir.join('XYZ')
    xyz.write('\n'.join(['2015-01-07 10:00:00 first task',
                         '2015-01-07 10:15:00 second task',
                         '2015-01-07 10:10:00 time order',
                         '2015-01-07 10:20:00 fourth task',
                         ]))
    with pytest.raises(SystemExit) as err:
        opts = optparse.Values({'filename': xyz.strpath,
                                'start': '2015.0107',
                                'end': '2015.0107',
                                'dayflag': False})
        wr.write_report(opts, True)
    assert_includes(str(err), 'Dates or times out of order')
Beispiel #2
0
def test_standalone_category(tmpdir, fx_stddata, fx_wrprep):
    """
    test standalone categories like 'vacation' and 'holiday'
    """
    pytest.debug_func()
    opts = optparse.Values({'filename': fx_stddata.file.strpath,
                            'start': '2009.0721',
                            'end': '2009.0724',
                            'dayflag': False})
    r = wr.write_report(opts, True)
    assert_includes(r, '27:58:49')
Beispiel #3
0
def test_start_date_missing(tmpdir, fx_stddata, fx_wrprep):
    """
    Calculate a week when the first few dates are missing
    """
    pytest.debug_func()
    opts = optparse.Values({'filename': fx_stddata.file.strpath,
                            'start': '2009.0718',
                            'end': '2009.0722',
                            'dayflag': False})
    r = wr.write_report(opts, True)
    assert_excludes(r, '24.0')
    assert_excludes(r, '2009.0719')
    assert_includes(r, '16:29:06 (16.4)')
Beispiel #4
0
def test_rounding(tmpdir, fx_stddata, fx_wrprep):
    """
    Test that calculations round properly. There are five types of duration
    number in this report:

        line item hms - HH:MM:SS for a specific task
        subtotal hms - HH:MM:SS for a category of tasks
        subtotal fp - floating point hour.tenth version of subtotal hms
        total hms - HH:MM:SS total duration at the bottom
        total fp - floating point hour.tenth version of total hms

    The issue is that sometimes when we add up the subtotal hms values, the
    result is larger than the sum of all the subtotal fp values. I want the
    total fp to represent the sum of the subtotal fp's, as PALS does.
    """
    pytest.debug_func()
    opts = optparse.Values({'filename': fx_stddata.file.strpath,
                            'start': '2009.0721',
                            'end': '2009.0724',
                            'dayflag': False})
    r = wr.write_report(opts, True)
    htot = stot = fpsum = 0
    for line in r.split('\n'):
        # zap: result of parsing the string
        # hms: what HH:MM:SS matched
        # fp: what [\d.]+ matched
        # stot: total of lines
        # htot: total in header
        zap = re.findall('(\d\d:\d\d:\d\d)( \(([\d.]+)\))?', line)
        if 0 < len(zap):
            (hms, _, fp) = zap[0]
            if 'Total:' in line:
                # here we verify that the total fp matchs the sum of the
                # subtotal fp values even though the sum of the hms values
                # would be larger
                htot = float(fp)
                assert fp_close(htot, fpsum, 0.001)
                assert not fp_close(htot, phms(hms), 0.05)
            elif fp != '':
                # here we handle a subtotal header line
                if 0 < stot:
                    assert fp_close(stot, htot, 0.05)
                    stot = 0
                htot = float(fp)
                assert fp_close(htot, phms(hms), 0.05)
                fpsum += htot
            else:
                # here we handle a detail line
                stot += phms(hms)
        pass
Beispiel #5
0
def test_daily_subtotal(tmpdir, fx_stddata, fx_wrprep):
    """
    Test that generating a report with dayflag=True produces non-zero daily
    subtotals when appropriate
    """
    pytest.skip()
    pytest.debug_func()
    opts = optparse.Values({'filename': fx_stddata.file.strpath,
                            'match_regexp': 'admin',
                            'start': '2009.0721',
                            'end': '2009.0724',
                            'dayflag': True})
    r = wr.write_report(opts, True)
    subtotal = 0
    for line in r.split('\n'):
        (text, duration) = parse_report_line(line)
        if 'Total:' in text:
            assert duration == subtotal
            subtotal = 0
        else:
            subtotal += duration