Skip to content

Commit

Permalink
os.make_dirs is not a thing; os.makedirs is
Browse files Browse the repository at this point in the history
We were also missing any coverage for this codepath :(
  • Loading branch information
mattdangerw committed Jan 28, 2025
1 parent 63863ab commit 419c281
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion keras_hub/src/utils/preset_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def tf_copy_gfile_to_cache(preset, path):
try:
import tensorflow as tf

os.make_dirs(os.path.dirname(local_path), exist_ok=True)
os.makedirs(os.path.dirname(local_path), exist_ok=True)
tf.io.gfile.copy(url, local_path)
except Exception as e:
# gfile.copy will leave an empty file after an error.
Expand Down
12 changes: 12 additions & 0 deletions keras_hub/src/utils/preset_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ def test_preset_errors(self):
with self.assertRaisesRegex(ValueError, "class keras_hub>BortBackbone"):
BertBackbone.from_preset(preset_dir)

@pytest.mark.large
def test_tf_file_io(self):
# Load a model from Kaggle to use as a test model.
preset = "bert_tiny_en_uncased"
backbone = BertBackbone.from_preset(preset)
# Save the model on a local directory.
temp_dir = self.get_temp_dir()
local_preset_dir = os.path.join(temp_dir, "bert_preset")
backbone.save_to_preset(local_preset_dir)
# Load with "file://" which tf supports.
backbone = BertBackbone.from_preset("file://" + local_preset_dir)

@pytest.mark.large
def test_upload_empty_preset(self):
temp_dir = self.get_temp_dir()
Expand Down

0 comments on commit 419c281

Please sign in to comment.