Skip to content

Commit

Permalink
fix load function integration test hack
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Oct 7, 2024
1 parent ca46f20 commit 4b9736b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions exe/import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ int main(int ac, char** av) {
return 0;
}

auto input_files = std::vector<std::pair<fs::path, loader_config>>{};
auto input_files = std::vector<std::pair<std::string, loader_config>>{};
if (is_directory(in) && recursive) {
for (auto const& e : fs::directory_iterator(in)) {
if (is_directory(e) /* unpacked zip file */ ||
boost::algorithm::to_lower_copy(
e.path().extension().generic_string()) == ".zip") {
input_files.emplace_back(e.path(), c);
input_files.emplace_back(e.path().generic_string(), c);
}
}
} else if (exists(in) && !recursive) {
Expand Down
13 changes: 6 additions & 7 deletions include/nigiri/loader/load.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ namespace nigiri::loader {
struct assistance_times;
struct loader_config;

timetable load(
std::vector<std::pair<std::filesystem::path, loader_config>> const&,
finalize_options const&,
interval<date::sys_days> const&,
assistance_times* = nullptr,
shapes_storage_t* = nullptr,
bool ignore = false);
timetable load(std::vector<std::pair<std::string, loader_config>> const&,
finalize_options const&,
interval<date::sys_days> const&,
assistance_times* = nullptr,
shapes_storage_t* = nullptr,
bool ignore = false);

} // namespace nigiri::loader
27 changes: 14 additions & 13 deletions src/loader/load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ std::vector<std::unique_ptr<loader_interface>> get_loaders() {
return loaders;
}

timetable load(
std::vector<std::pair<std::filesystem::path, loader_config>> const& paths,
finalize_options const& finalize_opt,
interval<date::sys_days> const& date_range,
assistance_times* a,
shapes_storage_t* shapes,
bool ignore) {
timetable load(std::vector<std::pair<std::string, loader_config>> const& paths,
finalize_options const& finalize_opt,
interval<date::sys_days> const& date_range,
assistance_times* a,
shapes_storage_t* shapes,
bool ignore) {
auto const loaders = get_loaders();

auto tt = timetable{};
Expand All @@ -38,16 +37,18 @@ timetable load(
auto bitfields = hash_map<bitfield, bitfield_idx_t>{};
for (auto const [idx, in] : utl::enumerate(paths)) {
auto const& [path, local_config] = in;
auto const is_in_memory = path.starts_with("\n#");
auto const src = source_idx_t{idx};
auto const dir =
path.generic_string().starts_with("\n#")
// hack to load strings in integration tests
? std::make_unique<mem_dir>(mem_dir::read(path.generic_string()))
: make_dir(path);
auto const dir = is_in_memory
// hack to load strings in integration tests
? std::make_unique<mem_dir>(mem_dir::read(path))
: make_dir(path);
auto const it =
utl::find_if(loaders, [&](auto&& l) { return l->applicable(*dir); });
if (it != end(loaders)) {
log(log_lvl::info, "loader.load", "loading {}", path);
if (!is_in_memory) {
log(log_lvl::info, "loader.load", "loading {}", path);
}
(*it)->load(local_config, src, *dir, tt, bitfields, a, shapes);
} else if (!ignore) {
throw utl::fail("no loader for {} found", path);
Expand Down

0 comments on commit 4b9736b

Please sign in to comment.