Ejemplo n.º 1
0
def test_datetime_to_timestamp():
    tss = [0, 0.5, -0.5, 12345.6789, -12345.6789, 1535910708.7767508]
    for ts in tss:
        t = datetime.datetime.utcfromtimestamp(ts)
        ts2 = util.datetime_to_timestamp(t)
        assert abs(ts - ts2) <= 0.5

    # Check rounding
    ts = datetime.datetime(1970, 1, 1, 0, 0, 0, 500000)
    assert util.datetime_to_timestamp(ts) == 1
    ts = datetime.datetime(1970, 1, 1, 0, 0, 0, 500000 - 1)
    assert util.datetime_to_timestamp(ts) == 0
Ejemplo n.º 2
0
def test_datetime_to_timestamp():
    tss = [0, 0.5, -0.5, 12345.6789, -12345.6789,
           1535910708.7767508]
    for ts in tss:
        t = datetime.datetime.utcfromtimestamp(ts)
        ts2 = util.datetime_to_timestamp(t)
        assert abs(ts - ts2) <= 0.5

    # Check rounding
    ts = datetime.datetime(1970, 1, 1, 0, 0, 0, 500000)
    assert util.datetime_to_timestamp(ts) == 1
    ts = datetime.datetime(1970, 1, 1, 0, 0, 0, 500000 - 1)
    assert util.datetime_to_timestamp(ts) == 0
Ejemplo n.º 3
0
    def tag(self, number):
        self._fake_date += datetime.timedelta(seconds=1)
        date = "{0} 0".format(util.datetime_to_timestamp(self._fake_date))

        self._repo.tag(['tag{0}'.format(number).encode(self.encoding)],
                       message="Tag {0}".format(number).encode(self.encoding),
                       date=date.encode(self.encoding))
Ejemplo n.º 4
0
def test_json_timestamp(tmpdir):
    # Check that per-benchmark timestamps are saved as JS timestamps in the result file
    tmpdir = six.text_type(tmpdir)

    stamp0 = datetime.datetime(1970, 1, 1)
    stamp1 = datetime.datetime(1971, 1, 1)
    duration = 1.5

    r = results.Results({'machine': 'mach'}, {}, 'aaaa',
                        util.datetime_to_timestamp(stamp0), 'py', 'env', {})
    value = runner.BenchmarkResult(result=[42],
                                   samples=[None],
                                   number=[None],
                                   profile=None,
                                   errcode=0,
                                   stderr='')
    benchmark = {
        'name': 'some_benchmark',
        'version': 'some version',
        'params': []
    }
    r.add_result(benchmark, value, started_at=stamp1, duration=duration)
    r.save(tmpdir)

    r = util.load_json(join(tmpdir, 'mach', 'aaaa-env.json'))
    keys = r['result_columns']
    values = dict(zip(keys, r['results']['some_benchmark']))
    assert values['started_at'] == util.datetime_to_js_timestamp(stamp1)
    assert values['duration'] == duration
Ejemplo n.º 5
0
def test_json_timestamp(tmpdir):
    # Check that per-benchmark timestamps are saved as JS timestamps in the result file
    tmpdir = six.text_type(tmpdir)

    stamp0 = datetime.datetime(1970, 1, 1)
    stamp1 = datetime.datetime(1971, 1, 1)
    stamp2 = datetime.datetime.utcnow()

    r = results.Results({'machine': 'mach'}, {}, 'aaaa',
                        util.datetime_to_timestamp(stamp0), 'py', 'env')
    value = {
        'result': [42],
        'params': [],
        'stats': None,
        'samples': None,
        'number': None,
        'started_at': stamp1,
        'ended_at': stamp2
    }
    r.add_result('some_benchmark', value)
    r.save(tmpdir)

    r = util.load_json(join(tmpdir, 'mach', 'aaaa-env.json'))
    assert r['started_at']['some_benchmark'] == util.datetime_to_js_timestamp(
        stamp1)
    assert r['ended_at']['some_benchmark'] == util.datetime_to_js_timestamp(
        stamp2)
Ejemplo n.º 6
0
Archivo: tools.py Proyecto: hamogu/asv
    def tag(self, number):
        self._fake_date += datetime.timedelta(seconds=1)
        date = "{0} 0".format(util.datetime_to_timestamp(self._fake_date))

        self._repo.tag(
            ['tag{0}'.format(number)], message="Tag {0}".format(number),
            date=date)
Ejemplo n.º 7
0
Archivo: tools.py Proyecto: craig8/asv
    def commit(self, message, date=None):
        if date is None:
            self._fake_date += datetime.timedelta(seconds=1)
            date = self._fake_date
        date = "{0} 0".format(util.datetime_to_timestamp(date))

        self._repo.commit(message, date=date)
Ejemplo n.º 8
0
def test_json_timestamp(tmpdir):
    # Check that per-benchmark timestamps are saved as JS timestamps in the result file
    tmpdir = six.text_type(tmpdir)

    stamp0 = datetime.datetime(1970, 1, 1)
    stamp1 = datetime.datetime(1971, 1, 1)
    stamp2 = datetime.datetime.utcnow()

    r = results.Results({'machine': 'mach'}, {}, 'aaaa', util.datetime_to_timestamp(stamp0),
                        'py', 'env')
    value = runner.BenchmarkResult(
        result=[42],
        samples=[None],
        number=[None],
        profile=None,
        errcode=0,
        stderr=''
    )
    benchmark = {'name': 'some_benchmark', 'version': 'some version', 'params': []}
    r.add_result(benchmark, value, started_at=stamp1, ended_at=stamp2)
    r.save(tmpdir)

    r = util.load_json(join(tmpdir, 'mach', 'aaaa-env.json'))
    assert r['started_at']['some_benchmark'] == util.datetime_to_js_timestamp(stamp1)
    assert r['ended_at']['some_benchmark'] == util.datetime_to_js_timestamp(stamp2)
Ejemplo n.º 9
0
def test_json_timestamp(tmpdir):
    # Check that per-benchmark timestamps are saved as JS timestamps in the result file
    tmpdir = six.text_type(tmpdir)

    stamp0 = datetime.datetime(1970, 1, 1)
    stamp1 = datetime.datetime(1971, 1, 1)
    stamp2 = datetime.datetime.utcnow()

    r = results.Results({'machine': 'mach'}, {}, 'aaaa',
                        util.datetime_to_timestamp(stamp0), 'py', 'env')
    value = runner.BenchmarkResult(result=[42],
                                   params=[],
                                   stats=None,
                                   samples=None,
                                   started_at=stamp1,
                                   ended_at=stamp2,
                                   profile=None,
                                   errcode=0,
                                   stderr='')
    r.add_result('some_benchmark', value, "some version")
    r.save(tmpdir)

    r = util.load_json(join(tmpdir, 'mach', 'aaaa-env.json'))
    assert r['started_at']['some_benchmark'] == util.datetime_to_js_timestamp(
        stamp1)
    assert r['ended_at']['some_benchmark'] == util.datetime_to_js_timestamp(
        stamp2)
Ejemplo n.º 10
0
def test_json_timestamp(tmpdir):
    # Check that per-benchmark timestamps are saved as JS timestamps in the result file
    tmpdir = six.text_type(tmpdir)

    stamp0 = datetime.datetime(1970, 1, 1)
    stamp1 = datetime.datetime(1971, 1, 1)
    stamp2 = datetime.datetime.utcnow()

    r = results.Results({'machine': 'mach'}, {}, 'aaaa', util.datetime_to_timestamp(stamp0),
                        'py', 'env')
    value = {
        'result': [42],
        'params': [],
        'stats': None,
        'samples': None,
        'number': None,
        'started_at': stamp1,
        'ended_at': stamp2
    }
    r.add_result('some_benchmark', value, "some version")
    r.save(tmpdir)

    r = util.load_json(join(tmpdir, 'mach', 'aaaa-env.json'))
    assert r['started_at']['some_benchmark'] == util.datetime_to_js_timestamp(stamp1)
    assert r['ended_at']['some_benchmark'] == util.datetime_to_js_timestamp(stamp2)
Ejemplo n.º 11
0
    def commit(self, message, date=None):
        if date is None:
            self._fake_date += datetime.timedelta(seconds=1)
            date = self._fake_date
        date = "{0} 0".format(util.datetime_to_timestamp(date))

        self._repo.commit(message, date=date)
Ejemplo n.º 12
0
Archivo: tools.py Proyecto: hamogu/asv
    def commit(self, message):
        # We explicitly override the date here, or the commits
        # will all be in the same second and cause all kinds
        # of problems for asv
        self._fake_date += datetime.timedelta(seconds=1)
        date = "{0} 0".format(util.datetime_to_timestamp(self._fake_date))

        self._repo.commit(message, date=date)
Ejemplo n.º 13
0
    def commit(self, message):
        # We explicitly override the date here, or the commits
        # will all be in the same second and cause all kinds
        # of problems for asv
        self._fake_date += datetime.timedelta(seconds=1)
        date = "{0} 0".format(util.datetime_to_timestamp(self._fake_date))

        self._repo.commit(message, date=date)
Ejemplo n.º 14
0
def test_json_timestamp(tmpdir):
    # Check that per-benchmark timestamps are saved as JS timestamps in the result file
    tmpdir = six.text_type(tmpdir)

    stamp0 = datetime.datetime(1970, 1, 1)
    stamp1 = datetime.datetime(1971, 1, 1)
    stamp2 = datetime.datetime.utcnow()

    r = results.Results({'machine': 'mach'}, {}, 'aaaa', util.datetime_to_timestamp(stamp0),
                        'py', 'env')
    r.add_result('some_benchmark', 42, stamp1, stamp2)
    r.save(tmpdir)

    r = util.load_json(join(tmpdir, 'mach', 'aaaa-env.json'))
    assert r['started_at']['some_benchmark'] == util.datetime_to_js_timestamp(stamp1)
    assert r['ended_at']['some_benchmark'] == util.datetime_to_js_timestamp(stamp2)