11import io
22import json
3+ import os
34import struct
45import zipfile
56from collections import defaultdict
@@ -635,15 +636,17 @@ def test_get_data_type_from_path_deleted():
635636 assert data_type == "HealthKitV2Samples_Deleted"
636637
637638
638- import os
639-
640-
641639def test_get_expected_raw_key_case1 ():
642640 raw_key_prefix = "test-raw_key_prefix/json"
643641 data_type = "test-data-type"
644642 cohort = "test-cohort"
645643 path = "path/to/FitbitIntradayCombined_20241111-20241112.json"
646- expected_key = f"{ raw_key_prefix } /dataset={ data_type } /cohort={ cohort } /FitbitIntradayCombined_20241111-20241112.ndjson.gz"
644+ expected_key = os .path .join (
645+ raw_key_prefix ,
646+ f"dataset={ data_type } " ,
647+ f"cohort={ cohort } " ,
648+ "FitbitIntradayCombined_20241111-20241112.ndjson.gz" ,
649+ )
647650 assert (
648651 app .get_expected_raw_key (raw_key_prefix , data_type , cohort , path )
649652 == expected_key
@@ -655,7 +658,12 @@ def test_get_expected_raw_key_case2():
655658 data_type = "test-data-type"
656659 cohort = "test-cohort"
657660 path = "path/to/HealthKitV2Samples_AppleStandTime_20241111-20241112.json"
658- expected_key = f"{ raw_key_prefix } /dataset={ data_type } /cohort={ cohort } /HealthKitV2Samples_AppleStandTime_20241111-20241112.ndjson.gz"
661+ expected_key = os .path .join (
662+ raw_key_prefix ,
663+ f"dataset={ data_type } " ,
664+ f"cohort={ cohort } " ,
665+ "HealthKitV2Samples_AppleStandTime_20241111-20241112.ndjson.gz" ,
666+ )
659667 assert (
660668 app .get_expected_raw_key (raw_key_prefix , data_type , cohort , path )
661669 == expected_key
@@ -667,7 +675,29 @@ def test_get_expected_raw_key_case3():
667675 data_type = "test-data-type"
668676 cohort = "test-cohort"
669677 path = "path/to/HealthKitV2Samples_AppleStandTime_Deleted_20241111-20241112.json"
670- expected_key = f"{ raw_key_prefix } /dataset={ data_type } /cohort={ cohort } /HealthKitV2Samples_AppleStandTime_Deleted_20241111-20241112.ndjson.gz"
678+ expected_key = os .path .join (
679+ raw_key_prefix ,
680+ f"dataset={ data_type } " ,
681+ f"cohort={ cohort } " ,
682+ "HealthKitV2Samples_AppleStandTime_Deleted_20241111-20241112.ndjson.gz" ,
683+ )
684+ assert (
685+ app .get_expected_raw_key (raw_key_prefix , data_type , cohort , path )
686+ == expected_key
687+ )
688+
689+
690+ def test_get_expected_raw_key_trailing_slash ():
691+ raw_key_prefix = "test-raw_key_prefix/json/"
692+ data_type = "test-data-type"
693+ cohort = "test-cohort"
694+ path = "path/to/HealthKitV2Samples_AppleStandTime_Deleted_20241111-20241112.json"
695+ expected_key = os .path .join (
696+ raw_key_prefix ,
697+ f"dataset={ data_type } " ,
698+ f"cohort={ cohort } " ,
699+ "HealthKitV2Samples_AppleStandTime_Deleted_20241111-20241112.ndjson.gz" ,
700+ )
671701 assert (
672702 app .get_expected_raw_key (raw_key_prefix , data_type , cohort , path )
673703 == expected_key
0 commit comments