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 Artem Pavlenko
parent c07397e71b
commit 13d678d9af
4 changed files with 68 additions and 33 deletions

@ -1 +1 @@
Subproject commit 817df2ff5dbe6de95b33a9e5e0516b3a3308a33d Subproject commit 7a8f60815c2962db6eb8977e0dd75740096f0c00

View file

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

View file

@ -34,6 +34,15 @@
namespace visual_tests namespace visual_tests
{ {
struct renderer_name_visitor
{
template <typename Renderer>
std::string operator()(Renderer const&) const
{
return Renderer::renderer_type::name;
}
};
class renderer_visitor class renderer_visitor
{ {
public: public:
@ -249,6 +258,44 @@ result_list runner::test_range(files_iterator begin,
return results; 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, result_list runner::test_one(runner::path_type const& style_path,
report_type & report, report_type & report,
std::atomic<std::size_t> & fail_count) const std::atomic<std::size_t> & fail_count) const
@ -272,39 +319,13 @@ result_list runner::test_one(runner::path_type const& style_path,
throw; 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 (!cfg.status)
if (!*status)
{ {
return results; 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()); std::string name(style_path.stem().string());
for (auto const & size : cfg.sizes) for (auto const & size : cfg.sizes)
@ -324,10 +345,16 @@ result_list runner::test_one(runner::path_type const& style_path,
for (auto const & ren : renderers_) for (auto const & ren : renderers_)
{ {
map.resize(size.width, size.height); std::string renderer_name = mapnik::util::apply_visitor(renderer_name_visitor(), ren);
if (box.valid()) 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 else
{ {

View file

@ -57,6 +57,7 @@ private:
result_list test_one(path_type const & style_path, result_list test_one(path_type const & style_path,
report_type & report, report_type & report,
std::atomic<std::size_t> & fail_limit) const; std::atomic<std::size_t> & fail_limit) const;
void parse_params(mapnik::parameters const & params, config & cfg) const;
const path_type styles_dir_; const path_type styles_dir_;
const config defaults_; const config defaults_;