浏览代码

Changes per feedback review. Changed ctest script to be consistent. Removed unused tests

Signed-off-by: Chiang <[email protected]>
Chiang 2 年之前
父节点
当前提交
9e82b4b677

+ 10 - 16
scripts/metrics/ctest_metrics_xml_to_csv.py

@@ -19,13 +19,6 @@ DEFAULT_CTEST_LOG_FILENAME = 'Test.xml'
 TAG_FILE = 'TAG'
 TESTING_DIR = 'Testing'
 
-
-def _get_default_csv_filename():
-    # Format default file name based off of date
-    now = datetime.datetime.now()
-    return f"{now.year}_{now.month:02d}_{now.day:02d}_{now.hour:02d}_{now.minute:02d}.csv"
-
-
 # Setup logging.
 logger = logging.get_logger("test_metrics")
 logging.setup_logger(logger)
@@ -38,6 +31,12 @@ CTEST_FIELDS_HEADER = [
 ]
 
 
+def _get_default_csv_filename():
+    # Format default file name based off of date
+    now = datetime.datetime.isoformat(datetime.datetime.now(tz=datetime.timezone.utc), timespec='seconds')
+    return f"{now.replace('+00:00', 'Z').replace('-', '_').replace('.', '_').replace(':', '_')}.csv"
+
+
 def main():
     # Parse args
     args = parse_args()
@@ -47,9 +46,8 @@ def main():
 
     # Create csv file
     full_path = os.path.join(args.output_directory, args.branch)
-    if args.weeks:
-        week = datetime.datetime.now().isocalendar().week
-        full_path = os.path.join(full_path, f"Week{week:02d}")
+    week = datetime.datetime.now().isocalendar().week
+    full_path = os.path.join(full_path, f"Week{week:02d}")
     full_path = os.path.join(full_path, args.csv_file)
     if os.path.exists(full_path):
         logger.warning(f"The file {full_path} already exists. It will be overridden.")
@@ -82,17 +80,13 @@ def parse_args():
         help=f"The directory and file name for the csv to be saved (defaults to YYYY_MM_DD_HH_mm)."
     )
     parser.add_argument(
-        "-o", "--output-directory", action="store", default="",
+        "-o", "--output-directory", action="store", default=os.getcwd(),
         help=f"The directory where the csv to be saved. Prepends the --csv-file arg."
     )
     parser.add_argument(
-        "-b", "--branch", action="store", default="",
+        "-b", "--branch", action="store", default="UnknownBranch",
         help="The branch the metrics were generated on. Used for directory saving."
     )
-    parser.add_argument(
-        "-w", "--weeks", action="store_true",
-        help="Boolean whether to include the week number in the created csv path."
-    )
 
     args = parser.parse_args()
     return args

+ 17 - 22
scripts/metrics/pytest_metrics_xml_to_csv.py

@@ -19,17 +19,6 @@ from common import logging, exception
 
 TESTING_DIR = 'Testing'
 
-
-def _get_default_csv_filename():
-    """
-    Returns a default filename to be saved in the format of YYYY_MM_DD_HH_mm_pytest.csv
-    :return: The filename as a string
-    """
-    # Format default file name based off of date
-    now = datetime.datetime.now(tz=datetime.timezone.utc)
-    return f"{now.year}_{now.month:02d}_{now.day:02d}_{now.hour:02d}_{now.minute:02d}_pytest.csv"
-
-
 # Setup logging.
 logger = logging.get_logger("test_metrics")
 logging.setup_logger(logger)
@@ -44,6 +33,16 @@ PYTEST_FIELDS_HEADER = [
 SIG_OWNER_CACHE = {}
 
 
+def _get_default_csv_filename():
+    """
+    Returns a default filename to be saved in the format of YYYY_MM_DDTHH_mm_SS_pytest.csv
+    :return: The filename as a string
+    """
+    # Format default file name based off of date
+    now = datetime.datetime.isoformat(datetime.datetime.now(tz=datetime.timezone.utc), timespec='seconds')
+    return f"{now.replace('+00:00', 'Z').replace('-', '_').replace('.', '_').replace(':', '_')}_pytest.csv"
+
+
 def main():
     """
     Creates the folder structure for metrics to be saved to S3 and converts Pytest xml's into csv format. This script
@@ -59,9 +58,8 @@ def main():
 
     # Create csv file
     full_path = os.path.join(args.output_directory, args.branch)
-    if args.weeks:
-        week = datetime.datetime.now().isocalendar().week
-        full_path = os.path.join(full_path, f"Week{week:02d}")
+    week = datetime.datetime.now().isocalendar().week
+    full_path = os.path.join(full_path, f"Week{week:02d}")
     full_path = os.path.join(full_path, args.csv_file)
     if os.path.exists(full_path):
         logger.warning(f"The file {full_path} already exists. It will be overridden.")
@@ -92,19 +90,16 @@ def parse_args():
     )
     parser.add_argument(
         "--csv-file", action="store", default=_get_default_csv_filename(),
-        help=f"The file name for the csv to be saved."
+        help=f"The file name for the csv to be saved. O3DE metrics pipeline will use default value."
     )
     parser.add_argument(
         "-o", "--output-directory", action="store", default=os.getcwd(),
-        help=f"The directory where the csv to be saved. Prepends the --csv-file arg."
-    )
-    parser.add_argument(
-        "-b", "--branch", action="store", default="",
-        help="The branch the metrics were generated on. Used for directory saving."
+        help=f"The directory where the csv to be saved. Prepends the --csv-file arg. O3DE metrics pipeline will use "
+             f"default value."
     )
     parser.add_argument(
-        "-w", "--weeks", action="store_true",
-        help="Boolean whether to include the week number in the created csv path."
+        "-b", "--branch", action="store", default="UnknownBranch",
+        help="The branch the metrics were generated on. O3DE metrics pipeline requires the branch name to be specified."
     )
     args = parser.parse_args()
     return args

+ 1 - 27
scripts/metrics/tests/test_metrics_xml_to_csv.py

@@ -6,6 +6,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT
 
 Unit tests for metrics_xml_to_csv.py
 """
+import datetime
 import unittest
 import unittest.mock as mock
 import os
@@ -15,33 +16,6 @@ import ctest_metrics_xml_to_csv
 
 class TestMetricsXMLtoCSV(unittest.TestCase):
 
-    @mock.patch("ctest_metrics_xml_to_csv.datetime.datetime")
-    def test_GetDefaultCSVFilename_SingleDigit_HasZeroes(self, mock_datetime):
-        mock_date = mock.MagicMock()
-        mock_date.month = 1
-        mock_date.day = 2
-        mock_date.year = "xxxx"
-        mock_date.hour = 3
-        mock_date.minute = 4
-        mock_datetime.now.return_value = mock_date
-
-        under_test = ctest_metrics_xml_to_csv._get_default_csv_filename()
-
-        assert under_test == "xxxx_01_02_03_04.csv"
-
-    @mock.patch("ctest_metrics_xml_to_csv.datetime.datetime")
-    def test_GetDefaultCSVFilename_DoubleDigit_NoZeroes(self, mock_datetime):
-        mock_date = mock.MagicMock()
-        mock_date.month = 11
-        mock_date.day = 12
-        mock_date.year = "xxxx"
-        mock_date.hour = 13
-        mock_date.minute = 14
-        mock_datetime.now.return_value = mock_date
-
-        under_test = ctest_metrics_xml_to_csv._get_default_csv_filename()
-
-        assert under_test == "xxxx_11_12_13_14.csv"
 
     @mock.patch('os.path.exists', mock.MagicMock(side_effect=[True, True]))
     @mock.patch('builtins.open')

+ 0 - 28
scripts/metrics/tests/test_pytest_metrics_xml_to_csv.py

@@ -14,34 +14,6 @@ import pytest_metrics_xml_to_csv
 
 class TestMetricsXMLtoCSV(unittest.TestCase):
 
-    @mock.patch("pytest_metrics_xml_to_csv.datetime.datetime")
-    def test_GetDefaultCSVFilename_SingleDigit_HasZeroes(self, mock_datetime):
-        mock_date = mock.MagicMock()
-        mock_date.month = 1
-        mock_date.day = 2
-        mock_date.year = "xxxx"
-        mock_date.hour = 3
-        mock_date.minute = 4
-        mock_datetime.now.return_value = mock_date
-
-        under_test = pytest_metrics_xml_to_csv._get_default_csv_filename()
-
-        assert under_test == "xxxx_01_02_03_04_pytest.csv"
-
-    @mock.patch("pytest_metrics_xml_to_csv.datetime.datetime")
-    def test_GetDefaultCSVFilename_DoubleDigit_NoZeroes(self, mock_datetime):
-        mock_date = mock.MagicMock()
-        mock_date.month = 11
-        mock_date.day = 12
-        mock_date.year = "xxxx"
-        mock_date.hour = 13
-        mock_date.minute = 14
-        mock_datetime.now.return_value = mock_date
-
-        under_test = pytest_metrics_xml_to_csv._get_default_csv_filename()
-
-        assert under_test == "xxxx_11_12_13_14_pytest.csv"
-
     def test_DetermineTestResult_FailedResult_ReturnsCorrectly(self):
         mock_node = mock.MagicMock()
         mock_node.find.return_value = True