visual tests: allow to ignore particular renderer (#3768)

* visual tests: refactor parsing parameters from the style

* visual tests: allow to ignore particular renderer

* update visual tests
This commit is contained in:
talaj 2017-09-14 15:21:30 +02:00 committed by Jiri Drbalek
parent 2e478ddd37
commit f8c6ad1e29
3 changed files with 67 additions and 32 deletions

View file

@ -25,12 +25,15 @@
// stl
#include <vector>
#include <set>
#include <string>
#include <chrono>
// boost
#include <boost/filesystem.hpp>
#include <mapnik/box2d.hpp>
namespace visual_tests
{
@ -47,12 +50,16 @@ struct config
config() : status(true),
scales({ 1.0, 2.0 }),
sizes({ { 500, 100 } }),
tiles({ { 1, 1 } }) { }
tiles({ { 1, 1 } }),
bbox(),
ignored_renderers() { }
bool status;
std::vector<double> scales;
std::vector<map_size> sizes;
std::vector<map_size> tiles;
mapnik::box2d<double> bbox;
std::set<std::string> ignored_renderers;
};
enum result_state : std::uint8_t

View file

@ -32,6 +32,15 @@
namespace visual_tests
{
struct renderer_name_visitor
{
template <typename Renderer>
std::string operator()(Renderer const&) const
{
return Renderer::renderer_type::name;
}
};
class renderer_visitor
{
public:
@ -247,6 +256,44 @@ result_list runner::test_range(files_iterator begin,
return results;
}
void runner::parse_params(mapnik::parameters const & params, config & cfg) const
{
cfg.status = *params.get<mapnik::value_bool>("status", cfg.status);
boost::optional<std::string> sizes = params.get<std::string>("sizes");
if (sizes)
{
cfg.sizes.clear();
parse_map_sizes(*sizes, cfg.sizes);
}
boost::optional<std::string> tiles = params.get<std::string>("tiles");
if (tiles)
{
cfg.tiles.clear();
parse_map_sizes(*tiles, cfg.tiles);
}
boost::optional<std::string> bbox_string = params.get<std::string>("bbox");
if (bbox_string)
{
cfg.bbox.from_string(*bbox_string);
}
for (auto const & renderer : renderers_)
{
std::string renderer_name = mapnik::util::apply_visitor(renderer_name_visitor(), renderer);
boost::optional<mapnik::value_bool> enabled = params.get<mapnik::value_bool>(renderer_name);
if (enabled && !*enabled)
{
cfg.ignored_renderers.insert(renderer_name);
}
}
}
result_list runner::test_one(runner::path_type const& style_path,
report_type & report,
std::atomic<std::size_t> & fail_count) const
@ -270,39 +317,13 @@ result_list runner::test_one(runner::path_type const& style_path,
throw;
}
mapnik::parameters const & params = map.get_extra_parameters();
parse_params(map.get_extra_parameters(), cfg);
boost::optional<mapnik::value_integer> status = params.get<mapnik::value_integer>("status", cfg.status);
if (!*status)
if (!cfg.status)
{
return results;
}
boost::optional<std::string> sizes = params.get<std::string>("sizes");
if (sizes)
{
cfg.sizes.clear();
parse_map_sizes(*sizes, cfg.sizes);
}
boost::optional<std::string> tiles = params.get<std::string>("tiles");
if (tiles)
{
cfg.tiles.clear();
parse_map_sizes(*tiles, cfg.tiles);
}
boost::optional<std::string> bbox_string = params.get<std::string>("bbox");
mapnik::box2d<double> box;
if (bbox_string)
{
box.from_string(*bbox_string);
}
std::string name(style_path.stem().string());
for (auto const & size : cfg.sizes)
@ -322,10 +343,16 @@ result_list runner::test_one(runner::path_type const& style_path,
for (auto const & ren : renderers_)
{
map.resize(size.width, size.height);
if (box.valid())
std::string renderer_name = mapnik::util::apply_visitor(renderer_name_visitor(), ren);
if (cfg.ignored_renderers.count(renderer_name))
{
map.zoom_to_box(box);
continue;
}
map.resize(size.width, size.height);
if (cfg.bbox.valid())
{
map.zoom_to_box(cfg.bbox);
}
else
{

View file

@ -59,6 +59,7 @@ private:
report_type & report,
std::atomic<std::size_t> & fail_limit) const;
void parse_map_sizes(std::string const & str, std::vector<map_size> & sizes) const;
void parse_params(mapnik::parameters const & params, config & cfg) const;
const map_sizes_grammar<std::string::const_iterator> map_sizes_parser_;
const path_type styles_dir_;