Jelajahi Sumber

Move timezone to ConfigOverride

Sam King 10 bulan lalu
induk
melakukan
7add98b834

+ 2 - 0
TrioTests/Info.plist

@@ -16,5 +16,7 @@
 	<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
 	<key>EnableReplayTests</key>
 	<string>$(ENABLE_REPLAY_TESTS)</string>
+	<key>ReplayTestTimezone</key>
+	<string>$(REPLAY_TEST_TIMEZONE)</string>
 </dict>
 </plist>

+ 1 - 8
TrioTests/OpenAPSSwiftTests/AutosensJsonTests.swift

@@ -160,14 +160,12 @@ import Testing
         "should produce same results for autosens for fixed JS",
         .enabled(if: ReplayTests.enabled)
     ) func replayErrorInputs() async throws {
-        let timezone = "America/Los_Angeles"
-        var skippedTimezones = Set<String>()
+        let timezone = ReplayTests.timezone
         let files = try await HttpFiles.listFiles()
         for filePath in files {
             let algorithmComparison = try await HttpFiles.downloadFile(at: filePath)
             print("Checking \(filePath) @ \(algorithmComparison.createdAt)")
             guard timezone == algorithmComparison.timezone else {
-                skippedTimezones.insert(algorithmComparison.timezone)
                 continue
             }
             guard let autosensInputs = algorithmComparison.autosensInput else {
@@ -188,11 +186,6 @@ import Testing
 
             timeZoneForTests.resetTimezone()
         }
-
-        print("Skipped timezones:")
-        for skippedTimezone in skippedTimezones {
-            print("  - \(skippedTimezone)")
-        }
     }
 
     @Test("Format autosens inputs for running in JS", .enabled(if: ReplayTests.enabled)) func formatInputs() async throws {

+ 4 - 0
TrioTests/OpenAPSSwiftTests/IobJsonTests.swift

@@ -44,9 +44,13 @@ import Testing
         .enabled(if: ReplayTests.enabled)
     ) func replayErrorInputs() async throws {
         let files = try await HttpFiles.listFiles()
+        let testingTimezone = ReplayTests.timezone
         for filePath in files {
             let algorithmComparison = try await HttpFiles.downloadFile(at: filePath)
             print("Checking \(filePath) @ \(algorithmComparison.createdAt)")
+            guard algorithmComparison.timezone == testingTimezone else {
+                continue
+            }
             guard let iobInputs = algorithmComparison.iobInput else {
                 print("Skipping, no iobInputs found")
                 if let str = algorithmComparison.comparisonError {

+ 1 - 13
TrioTests/OpenAPSSwiftTests/MealJsonTests.swift

@@ -12,15 +12,12 @@ import Testing
         // Note: This test case can only test one timezone per invocation
         // so you need to manually change this to try out errors from
         // different timezones
-        let testingTimezone = "Europe/Berlin"
+        let testingTimezone = ReplayTests.timezone
         let files = try await HttpFiles.listFiles()
-        var skippedTimezones = Set<String>()
         for filePath in files {
             let algorithmComparison = try await HttpFiles.downloadFile(at: filePath)
             print("Checking \(filePath) @ \(algorithmComparison.createdAt)")
             guard algorithmComparison.timezone == testingTimezone else {
-                print("Skipping timezone \(algorithmComparison.timezone)")
-                skippedTimezones.insert(algorithmComparison.timezone)
                 continue
             }
             guard let mealInputs = algorithmComparison.mealInput else {
@@ -40,15 +37,6 @@ import Testing
             print("Checked \(filePath) \(algorithmComparison.timezone)")
             timeZoneForTests.resetTimezone()
         }
-
-        if skippedTimezones.isEmpty {
-            print("Didn't skip any timezones")
-        } else {
-            print("Skipped timezones:")
-            for timezone in skippedTimezones {
-                print("  - \(timezone)")
-            }
-        }
     }
 
     func checkFixedJsAgainstSwift(mealInputs: MealInputs) async throws {

+ 12 - 0
TrioTests/OpenAPSSwiftTests/utils/ReplayTests.swift

@@ -13,4 +13,16 @@ enum ReplayTests {
         let bundle = Bundle(for: BundleReference.self)
         return bundle.object(forInfoDictionaryKey: "EnableReplayTests") as? String == "YES"
     }
+
+    /// Timezone to use for replay tests.
+    ///
+    /// This is used to filter replay test files by timezone. If not set, it defaults to "America/Los_Angeles".
+    /// To set it, add this line to your ConfigOverride.xcconfig file:
+    /// ```
+    /// REPLAY_TEST_TIMEZONE = Europe/Berlin
+    /// ```
+    static var timezone: String {
+        let bundle = Bundle(for: BundleReference.self)
+        return bundle.object(forInfoDictionaryKey: "ReplayTestTimezone") as? String ?? "America/Los_Angeles"
+    }
 }