Skip to content

Commit

Permalink
Merge pull request #125 from GatorEducator/feat/time-in-report
Browse files Browse the repository at this point in the history
Feat: add current time to json report
  • Loading branch information
Yanqiao4396 authored Jul 10, 2023
2 parents 2e091fd + 7761afc commit 11ead19
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 8 additions & 2 deletions gatorgrade/output/output.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Run checks and display whether each has passed or failed."""
import datetime
import json
import os
import subprocess
Expand Down Expand Up @@ -108,11 +109,13 @@ def create_report_json(
"""
# create list to hold the key values for the dictionary that
# will be converted into json
overall_key_list = ["amount_correct", "percentage_score", "checks"]
overall_key_list = ["amount_correct", "percentage_score", "report_time", "checks"]

checks_list = []
overall_dict = {}

report_generation_time = datetime.datetime.now()
formatted_time = report_generation_time.strftime("%Y-%m-%d %H:%M:%S")
# for each check:
for i in range(len(checkResults)):
# grab all of the information in it and add it to the checks list
Expand All @@ -126,7 +129,10 @@ def create_report_json(

# create the dictionary for all of the check information
overall_dict = dict(
zip(overall_key_list, [passed_count, percent_passed, checks_list])
zip(
overall_key_list,
[passed_count, percent_passed, formatted_time, checks_list],
)
)
return overall_dict

Expand Down
16 changes: 15 additions & 1 deletion tests/output/test_output.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test suite for output_functions.py."""

import datetime
import json
import os
import subprocess
Expand All @@ -10,6 +11,18 @@
from gatorgrade.input.checks import ShellCheck
from gatorgrade.output import output

FAKE_TIME = datetime.datetime(2022, 1, 1, 10, 30, 0)


@pytest.fixture
def patch_datetime_now(monkeypatch):
class mydatetime:
@classmethod
def now(cls):
return FAKE_TIME

monkeypatch.setattr(datetime, "datetime", mydatetime)


def test_run_checks_gg_check_should_show_passed(capsys):
"""Test that run_checks runs a GatorGrader check and prints that the check has passed."""
Expand Down Expand Up @@ -160,7 +173,7 @@ def test_run_checks_all_passed_prints_correct_summary(capsys):
assert "Passed 3/3 (100%) of checks" in out


def test_json_report_file_created_correctly():
def test_json_report_file_created_correctly(patch_datetime_now):
"""Test that with the cli input '--report file json insights.json' the file is created correctly."""
# given the following checks
checks = [
Expand Down Expand Up @@ -233,6 +246,7 @@ def test_json_report_file_created_correctly():
expected_file_contents_dict = {
"amount_correct": 1,
"percentage_score": 33,
"report_time": FAKE_TIME.strftime("%Y-%m-%d %H:%M:%S"),
"checks": [
{
"description": "Echo'Hello!'",
Expand Down

0 comments on commit 11ead19

Please sign in to comment.