def test_Testcase_GetOrAdd(session): proto = deepsmith_pb2.Testcase( toolchain='cpp', generator=deepsmith_pb2.Generator(name='generator', ), harness=deepsmith_pb2.Harness(name='harness', ), inputs={ 'src': 'void main() {}', 'data': '[1,2]' }, invariant_opts={'config': 'opt'}, profiling_events=[ deepsmith_pb2.ProfilingEvent( client='localhost', type='generate', duration_ms=100, event_start_epoch_ms=1021312312, ), deepsmith_pb2.ProfilingEvent( client='localhost', type='foo', duration_ms=100, event_start_epoch_ms=1230812312, ), ]) testcase = deeplearning.deepsmith.testcase.Testcase.GetOrAdd( session, proto) # NOTE: We have to flush so that SQLAlchemy resolves all of the object IDs. session.flush() assert testcase.toolchain.string == 'cpp' assert testcase.generator.name == 'generator' assert testcase.harness.name == 'harness' assert len(testcase.inputset) == 2 assert len(testcase.inputs) == 2 assert testcase.inputs['src'] == 'void main() {}' assert testcase.inputs['data'] == '[1,2]' assert len(testcase.invariant_optset) == 1 assert len(testcase.invariant_opts) == 1 assert testcase.invariant_opts['config'] == 'opt' assert testcase.profiling_events[0].client.string == 'localhost' assert testcase.profiling_events[0].type.string == 'generate' assert testcase.profiling_events[0].duration_ms == 100 assert (testcase.profiling_events[0].event_start == labdate.DatetimeFromMillisecondsTimestamp(1021312312)) assert testcase.profiling_events[1].client.string == 'localhost' assert testcase.profiling_events[1].type.string == 'foo' assert testcase.profiling_events[1].duration_ms == 100 assert (testcase.profiling_events[1].event_start == labdate.DatetimeFromMillisecondsTimestamp(1230812312))
def _GetArgsFromProto(proto: scrape_repos_pb2.GitHubRepoMetadata) -> \ typing.Dict[str, typing.Any]: date_scraped = labdate.DatetimeFromMillisecondsTimestamp( proto.scraped_utc_epoch_ms) return {"clone_from_url": proto.clone_from_url, "owner": proto.owner, "name": proto.name, "num_stars": proto.num_stars, "num_forks": proto.num_forks, "num_watchers": proto.num_watchers, "date_scraped": date_scraped, }
def date(self) -> typing.Optional[datetime.datetime]: """The date that the lock was acquired. Value is None if lock is unclaimed. """ lockfile = self.read(self.path) if lockfile.date_acquired_utc_epoch_ms: return labdate.DatetimeFromMillisecondsTimestamp( lockfile.date_acquired_utc_epoch_ms) else: return None
def GetOrAdd(cls, session: db.session_t, proto: deepsmith_pb2.ProfilingEvent, testcase: 'testcase.Testcase') -> 'ProfilingEvent': return sqlutil.GetOrAdd( session, cls, testcase=testcase, client=deeplearning.deepsmith.client.Client.GetOrAdd( session, proto.client), type=ProfilingEventType.GetOrAdd(session, proto.type), duration_ms=proto.duration_ms, event_start=labdate.DatetimeFromMillisecondsTimestamp( proto.event_start_epoch_ms))
def test_ConvertAbslLogToProtos_date_utc_epoch_ms(): p = logutil.ConertAbslLogToProtos("""\ I0527 23:14:18.903151 140735784891328 log_to_file.py:31] Hello, info! W0527 23:14:18.903151 140735784891328 log_to_file.py:31] Hello, warning! I0527 23:14:18.903151 140735784891328 log_to_file.py:31] Hello ... multiline! E0527 23:14:18.903151 140735784891328 log_to_file.py:31] Hello, error! F0527 23:14:18.903151 140735784891328 log_to_file.py:31] Hello, fatal! """) assert p[0].date_utc_epoch_ms == 1527462858903 assert p[1].date_utc_epoch_ms == 1527462858903 assert p[2].date_utc_epoch_ms == 1527462858903 assert p[3].date_utc_epoch_ms == 1527462858903 assert p[4].date_utc_epoch_ms == 1527462858903 dt = labdate.DatetimeFromMillisecondsTimestamp(p[0].date_utc_epoch_ms) assert dt.year == datetime.datetime.utcnow().year assert dt.month == 5 assert dt.day == 27 assert dt.hour == 23 assert dt.minute == 14 assert dt.second == 18 # Microsecond precision has been reduced to millisecond. assert dt.microsecond == 903000
def test_default_timestamp_datetime_equivalence(): now = labdate.GetUtcMillisecondsNow() timestamp = labdate.MillisecondsTimestamp() date_out = labdate.DatetimeFromMillisecondsTimestamp(timestamp) assert now.date() == date_out.date()
def test_timestamp_datetime_equivalence(): date_in = labdate.GetUtcMillisecondsNow() timestamp = labdate.MillisecondsTimestamp(date_in) date_out = labdate.DatetimeFromMillisecondsTimestamp(timestamp) assert date_in == date_out
def test_DatetimeFromMillisecondsTimestamp_negative_int(): with pytest.raises(ValueError): labdate.DatetimeFromMillisecondsTimestamp(-1)
def test_DatetimeFromMillisecondsTimestamp_invalid_argument(): with pytest.raises(TypeError): labdate.DatetimeFromMillisecondsTimestamp('not a timestamp')
def test_DatetimeFromMillisecondsTimestamp_default_argument(): """Current time is used if no timestamp provided.""" assert labdate.DatetimeFromMillisecondsTimestamp()