Skip to content

Commit

Permalink
Print generatedAt with timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
owickstrom committed Nov 18, 2022
1 parent a2ca09b commit e8c6d10
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions quickstrom/reporter/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from quickstrom.result import *
from quickstrom.reporter import Reporter
from pathlib import Path
from datetime import datetime
from datetime import datetime, timezone


@dataclass(frozen=True)
Expand All @@ -22,23 +22,27 @@ class JsonReporter(Reporter):
files_dir: Path

def report(self, result: PlainResult):
result_with_paths = write_screenshots(result, self.path.parent, self.files_dir)
result_with_paths = write_screenshots(result, self.path.parent,
self.files_dir)
report = Report(diff_result(result_with_paths), datetime.utcnow())
encode_file(report, self.path)


def write_screenshots(result: PlainResult,
base: Path,
def write_screenshots(result: PlainResult, base: Path,
dir: Path) -> ResultWithScreenshots[Path]:
os.makedirs(dir)

def on_state(
state: State[protocol.JsonLike,
bytes]) -> State[protocol.JsonLike, Path]:

if state.screenshot:
p = dir / Path(f"{state.hash}.png")
p.write_bytes(state.screenshot.image)
return State(state.hash, state.queries, Screenshot(p.relative_to(base), state.screenshot.width, state.screenshot.height, state.screenshot.scale))
return State(
state.hash, state.queries,
Screenshot(p.relative_to(base), state.screenshot.width,
state.screenshot.height, state.screenshot.scale))
else:
return State(state.hash, state.queries, None)

Expand All @@ -63,7 +67,8 @@ def default(self, o: Any):
if isinstance(o, Report):
return {
'result': self.default(o.result),
'generatedAt': str(o.generated_at),
'generatedAt':
o.generated_at.astimezone(timezone.utc).isoformat(),
'tag': 'Report'
}
elif isinstance(o, Passed):
Expand Down

0 comments on commit e8c6d10

Please sign in to comment.