Skip to content

Commit

Permalink
Only allow missing images/ in spatial_experiment version >= 1.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Nov 9, 2024
1 parent 0fb4fd4 commit 7ae1298
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/takane/spatial_experiment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ inline void validate_image(const std::filesystem::path& path, size_t i, const st

inline void validate_images(const std::filesystem::path& path, size_t ncols, Options& options, const ritsuko::Version& version) {
auto image_dir = path / "images";
if (!std::filesystem::exists(image_dir)) {
if (!std::filesystem::exists(image_dir) && version.ge(1, 2, 0)) {
// No images at all, which is permitted.
return;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/src/spatial_experiment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,20 @@ TEST_F(SpatialExperimentTest, NoImages) {
options.num_samples = 3;
options.num_images_per_sample = 0;
spatial_experiment::mock(dir, options);

std::filesystem::remove_all(dir / "images");
EXPECT_FALSE(std::filesystem::exists(dir / "images"));

// Bumping the version to support no images/ subdirectory.
{
auto opath = dir / "OBJECT";
auto parsed = millijson::parse_file(opath.c_str());
auto& remap = reinterpret_cast<millijson::Object*>(parsed.get())->values;
remap["type"] = std::shared_ptr<millijson::Base>(new millijson::String("spatial_experiment"));
spatial_experiment::add_object_metadata(parsed.get(), "1.2");
json_utils::dump(parsed.get(), opath);
}

test_validate(dir);
}

Expand Down

0 comments on commit 7ae1298

Please sign in to comment.