File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed
idf_component_tools/hash_tools
tests/idf_component_tools/hash_tools Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -46,11 +46,11 @@ def __init__(self, path: Path):
4646 def exists (self ) -> bool :
4747 """Check if checksums file exists.
4848
49- :return: True if checksums file exists, False otherwise
49+ :return: True if checksums file exists in the component directory , False otherwise.
5050 """
5151 return (self .path / CHECKSUMS_FILENAME ).is_file ()
5252
53- def dump (self ) -> None :
53+ def dump (self , path : t . Optional [ Path ] = None ) -> None :
5454 """Writes checksums to a file.
5555
5656 Format of the file is:
@@ -68,8 +68,13 @@ def dump(self) -> None:
6868 ...
6969 ]
7070 }
71+
72+ :param path: Path to directory where checksums file will be created.
73+ If None, uses the component path provided during initialization.
7174 """
7275
76+ checksums_path = (path if path is not None else self .path ) / CHECKSUMS_FILENAME
77+
7378 checksums = ChecksumsModel (
7479 files = [
7580 FileField (
@@ -82,7 +87,7 @@ def dump(self) -> None:
8287 ]
8388 )
8489
85- ( self . path / CHECKSUMS_FILENAME ) .write_text (checksums .model_dump_json ())
90+ checksums_path .write_text (checksums .model_dump_json ())
8691
8792 def load (self ) -> ChecksumsModel :
8893 """Load file with checksums.
Original file line number Diff line number Diff line change @@ -75,6 +75,34 @@ def test_checksums_dump(tmp_path, checksums_model):
7575 assert stored_checksums == expected_checksums
7676
7777
78+ def test_checksums_dump_to_other_path (tmp_path , checksums_model ):
79+ component_path = tmp_path / 'component'
80+ component_path .mkdir ()
81+ (component_path / 'file1.txt' ).write_text ('file1' )
82+ checksums_manager = ChecksumsManager (component_path )
83+
84+ checksums_model .files .append (
85+ create_file_field (
86+ 'file1.txt' , 5 , 'c147efcfc2d7ea666a9e4f5187b115c90903f0fc896a56df9a6ef5d8f3fc9f31'
87+ )
88+ )
89+
90+ external_path = tmp_path / 'ext'
91+ external_path .mkdir ()
92+ checksums_path = external_path / CHECKSUMS_FILENAME
93+
94+ checksums_manager .dump (external_path )
95+ assert checksums_path .is_file ()
96+
97+ stored_checksums = json .loads (checksums_path .read_text ())
98+ expected_checksums = checksums_model .model_dump ()
99+
100+ normalize_checksums (stored_checksums )
101+ normalize_checksums (expected_checksums )
102+
103+ assert stored_checksums == expected_checksums
104+
105+
78106def test_load_checksums (tmp_path , checksums_model ):
79107 checksums_path = tmp_path / CHECKSUMS_FILENAME
80108 checksums_manager = ChecksumsManager (tmp_path )
You can’t perform that action at this time.
0 commit comments