Merge commit '70008ca78188a086174b003ef965a67a6e93e79e' into harfbuzz

This commit is contained in:
Hermann Kraus 2013-03-16 16:07:50 +01:00
commit 4699d2d0d6
23 changed files with 464 additions and 132 deletions

View file

@ -16,23 +16,24 @@ mapnik:
clean:
@python scons/scons.py -c --config=cache --implicit-cache --max-drift=1
@if test -e ".sconsign.dblite"; then rm ".sconsign.dblite"; fi
@if test -e "config.log"; then rm "config.log"; fi
@if test -e ".sconf_temp/"; then rm -r ".sconf_temp/"; fi
@find ./ -name "*.os" -exec rm {} \;
@find ./ -name "*.o" -exec rm {} \;
@find ./ -name "*.pyc" -exec rm {} \;
@rm bindings/python/mapnik/paths.py
distclean:
if test -e "config.cache"; then rm -r "config.cache"; fi
if test -e "config.log"; then rm -r "config.log"; fi
if test -e ".sconf_temp/"; then rm -r ".sconf_temp/"; fi
if test -e ".sconsign.dblite"; then rm ".sconsign.dblite"; fi
if test -e "config.cache"; then rm "config.cache"; fi
@if test -e "config.cache"; then rm "config.cache"; fi
if test -e "config.py"; then mv "config.py" "config.py.backup"; fi
reset: distclean
rebuild:
make uninstall && make clean && time make && make install
uninstall:
python scons/scons.py --config=cache --implicit-cache --max-drift=1 uninstall
@python scons/scons.py --config=cache --implicit-cache --max-drift=1 uninstall
test:
@ ./run_tests

View file

@ -2,6 +2,7 @@
#include <mapnik/image_data.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/image_reader.hpp>
#include <mapnik/util/conversions.hpp>
// stl
@ -9,10 +10,12 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdio>
// boost
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/bind.hpp>
#define BOOST_CHRONO_HEADER_ONLY
#include <boost/chrono/process_cpu_clocks.hpp>
@ -29,8 +32,25 @@ template <typename T>
void benchmark(T test, std::string const& name)
{
if (!test.validate()) throw std::runtime_error(std::string("test did not validate: ") + name);
dur elapsed = test.run();
std::clog << name << ": " << boost::chrono::duration_cast<milliseconds>(elapsed) << "\n";
process_cpu_clock::time_point start;
dur elapsed;
if (test.threads_ > 0) {
boost::thread_group tg;
for (unsigned i=0;i<test.threads_;++i)
{
tg.create_thread(test);
}
start = process_cpu_clock::now();
tg.join_all();
elapsed = process_cpu_clock::now() - start;
} else {
start = process_cpu_clock::now();
test();
elapsed = process_cpu_clock::now() - start;
}
std::clog << (test.threads_ ? "threaded -> ": "")
<< name << ": "
<< boost::chrono::duration_cast<milliseconds>(elapsed) << "\n";
}
bool compare_images(std::string const& src_fn,std::string const& dest_fn)
@ -50,7 +70,7 @@ bool compare_images(std::string const& src_fn,std::string const& dest_fn)
}
boost::shared_ptr<image_32> image_ptr2 = boost::make_shared<image_32>(reader2->width(),reader2->height());
reader2->read(0,0,image_ptr2->data());
image_data_32 const& dest = image_ptr1->data();
image_data_32 const& src = image_ptr2->data();
@ -72,35 +92,36 @@ bool compare_images(std::string const& src_fn,std::string const& dest_fn)
struct test1
{
unsigned iter_;
explicit test1(unsigned iterations) :
iter_(iterations) {}
unsigned threads_;
explicit test1(unsigned iterations, unsigned threads=0) :
iter_(iterations),
threads_(threads)
{}
bool validate()
{
return true;
}
dur run()
void operator()()
{
mapnik::image_data_32 im(256,256);
std::string out;
process_cpu_clock::time_point start = process_cpu_clock::now();
for (int i=0;i<iter_;++i) {
for (unsigned i=0;i<iter_;++i) {
out.clear();
out = mapnik::save_to_string(im,"png");
}
return process_cpu_clock::now() - start;
}
};
struct test2
{
unsigned iter_;
unsigned threads_;
boost::shared_ptr<image_32> im_;
explicit test2(unsigned iterations) :
explicit test2(unsigned iterations, unsigned threads=0) :
iter_(iterations),
threads_(threads),
im_()
{
std::string filename("./benchmark/data/multicolor.png");
@ -112,7 +133,7 @@ struct test2
im_ = boost::make_shared<image_32>(reader->width(),reader->height());
reader->read(0,0,im_->data());
}
bool validate()
{
std::string expected("./benchmark/data/multicolor-hextree-expected.png");
@ -120,20 +141,113 @@ struct test2
mapnik::save_to_file(im_->data(),actual, "png8:m=h");
return compare_images(actual,expected);
}
dur run()
void operator()()
{
std::string out;
process_cpu_clock::time_point start = process_cpu_clock::now();
for (int i=0;i<iter_;++i) {
for (unsigned i=0;i<iter_;++i) {
out.clear();
out = mapnik::save_to_string(im_->data(),"png8:m=h");
}
return process_cpu_clock::now() - start;
}
};
struct test3
{
unsigned iter_;
unsigned threads_;
double val_;
explicit test3(unsigned iterations, unsigned threads=0) :
iter_(iterations),
threads_(threads),
val_(-0.123) {}
bool validate()
{
std::ostringstream s;
s << val_;
return (s.str() == "-0.123");
}
void operator()()
{
std::string out;
for (unsigned i=0;i<iter_;++i) {
std::ostringstream s;
s << val_;
out = s.str();
}
}
};
struct test4
{
unsigned iter_;
unsigned threads_;
double val_;
explicit test4(unsigned iterations, unsigned threads=0) :
iter_(iterations),
threads_(threads),
val_(-0.123) {}
bool validate()
{
std::string s;
mapnik::util::to_string(s,val_);
return (s == "-0.123");
}
void operator()()
{
std::string out;
for (unsigned i=0;i<iter_;++i) {
out.clear();
mapnik::util::to_string(out,val_);
}
}
};
struct test5
{
unsigned iter_;
unsigned threads_;
double val_;
explicit test5(unsigned iterations, unsigned threads=0) :
iter_(iterations),
threads_(threads),
val_(-0.123) {}
bool validate()
{
std::string s;
to_string_impl(s,val_);
return (s == "-0.123");
}
bool to_string_impl(std::string &s , double val)
{
s.resize(s.capacity());
while (true)
{
size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%g", val_));
if (n2 <= s.size())
{
s.resize(n2);
break;
}
s.resize(n2);
}
return true;
}
void operator()()
{
std::string out;
for (unsigned i=0;i<iter_;++i)
{
out.clear();
to_string_impl(out , val_);
}
}
};
int main( int, char*[] )
{
@ -141,13 +255,53 @@ int main( int, char*[] )
{
std::cout << "starting benchmark…\n";
{
test1 runner(100);
benchmark(runner,"encoding blank image as png");
test1 runner(100);
benchmark(runner,"encoding blank image as png");
}
{
test2 runner(100);
benchmark(runner,"encoding multicolor image as png8:m=h");
test2 runner(100);
benchmark(runner,"encoding multicolor image as png8:m=h");
}
{
test1 runner(10,10);
benchmark(runner,"encoding blank image as png");
}
{
test2 runner(10,10);
benchmark(runner,"encoding multicolor image as png8:m=h");
}
{
test3 runner(1000000);
benchmark(runner,"double to string conversion with std::ostringstream");
}
{
test4 runner(1000000);
benchmark(runner,"double to string conversion with mapnik::util_to_string");
}
{
test5 runner(1000000);
benchmark(runner,"double to string conversion with snprintf");
}
{
test3 runner(1000000,10);
benchmark(runner,"double to string conversion with std::ostringstream");
}
{
test4 runner(1000000,10);
benchmark(runner,"double to string conversion with mapnik::util_to_string");
}
{
test5 runner(1000000,10);
benchmark(runner,"double to string conversion with snprintf");
}
std::cout << "...benchmark done\n";
@ -158,4 +312,4 @@ int main( int, char*[] )
std::clog << "test error: " << ex.what() << "\n";
return -1;
}
}
}

View file

@ -25,6 +25,7 @@
// mapnik
#include <mapnik/color.hpp>
#include <mapnik/config.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/expression.hpp>

View file

@ -34,6 +34,7 @@ struct MAPNIK_DECL debug_symbolizer :
{
debug_symbolizer() : symbolizer_base() {}
};
}
#endif // DEBUG_SYMBOLIZER_HPP

View file

@ -235,7 +235,7 @@ public:
geometry_type const& geom = get_geometry(i);
if (i==0)
{
box2d<double> const& box = geom.envelope();
box2d<double> box = geom.envelope();
result.init(box.minx(),box.miny(),box.maxx(),box.maxy());
}
else

View file

@ -24,8 +24,9 @@
#define MAPNIK_LINE_PATTERN_SYMBOLIZER_HPP
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/symbolizer.hpp>
//#include <boost/shared_ptr.hpp>
#include <mapnik/path_expression.hpp>
namespace mapnik
{

View file

@ -24,6 +24,8 @@
#define MAPNIK_LINE_SYMBOLIZER_HPP
// mapnik
#include <mapnik/color.hpp>
#include <mapnik/config.hpp>
#include <mapnik/stroke.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/enumeration.hpp>

View file

@ -24,12 +24,13 @@
#define MAPNIK_MARKERS_SYMBOLIZER_HPP
//mapnik
#include <mapnik/symbolizer.hpp>
#include <mapnik/parse_path.hpp>
#include <mapnik/color.hpp>
#include <mapnik/config.hpp>
#include <mapnik/stroke.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/enumeration.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/path_expression.hpp>
// boost
#include <boost/optional.hpp>

View file

@ -28,7 +28,7 @@
#include <mapnik/feature_layer_desc.hpp>
// stl
#include <vector>
#include <deque>
namespace mapnik {
@ -48,7 +48,7 @@ public:
size_t size() const;
void clear();
private:
std::vector<feature_ptr> features_;
std::deque<feature_ptr> features_;
mapnik::layer_descriptor desc_;
datasource::datasource_t type_;
bool bbox_check_;

View file

@ -45,7 +45,7 @@ public:
bbox_check_(bbox_check)
{}
memory_featureset(box2d<double> const& bbox, std::vector<feature_ptr> const& features, bool bbox_check = true)
memory_featureset(box2d<double> const& bbox, std::deque<feature_ptr> const& features, bool bbox_check = true)
: bbox_(bbox),
pos_(features.begin()),
end_(features.end()),
@ -92,8 +92,8 @@ public:
private:
box2d<double> bbox_;
std::vector<feature_ptr>::const_iterator pos_;
std::vector<feature_ptr>::const_iterator end_;
std::deque<feature_ptr>::const_iterator pos_;
std::deque<feature_ptr>::const_iterator end_;
datasource::datasource_t type_;
bool bbox_check_;
};

View file

@ -24,6 +24,7 @@
#define MAPNIK_POINT_SYMBOLIZER_HPP
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/enumeration.hpp>

View file

@ -24,6 +24,8 @@
#define MAPNIK_POLYGON_PATTERN_SYMBOLIZER_HPP
// mapnik
#include <mapnik/color.hpp>
#include <mapnik/config.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/enumeration.hpp>
#include <mapnik/gamma_method.hpp>

View file

@ -25,8 +25,8 @@
// mapnik
#include <mapnik/color.hpp>
#include <mapnik/config.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/enumeration.hpp>
#include <mapnik/gamma_method.hpp>
namespace mapnik

View file

@ -24,14 +24,17 @@
#define MAPNIK_RASTER_SYMBOLIZER_HPP
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/raster_colorizer.hpp>
#include <mapnik/image_scaling.hpp>
// boost
#include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
//stl
#include <string>
namespace mapnik
{

View file

@ -24,11 +24,13 @@
#define MAPNIK_SHIELD_SYMBOLIZER_HPP
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/color.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/text_symbolizer.hpp>
// boost
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>
namespace mapnik

View file

@ -38,6 +38,7 @@
// stl
#include <vector>
#include <deque>
#include <string>
class csv_datasource : public mapnik::datasource
@ -66,7 +67,7 @@ private:
std::string inline_string_;
unsigned file_length_;
mapnik::value_integer row_limit_;
std::vector<mapnik::feature_ptr> features_;
std::deque<mapnik::feature_ptr> features_;
std::string escape_;
std::string separator_;
std::string quote_;

View file

@ -159,7 +159,7 @@ sqlite_datasource::sqlite_datasource(parameters const& params)
{
std::vector<std::string> tables;
sqlite_utils::get_tables(dataset_,tables);
if (*table_by_index >= tables.size())
if (*table_by_index < 0 || *table_by_index >= static_cast<int>(tables.size()))
{
std::ostringstream s;
s << "SQLite Plugin: only "

View file

@ -24,7 +24,8 @@
#include <mapnik/util/conversions.hpp>
#include <mapnik/value_types.hpp>
// boost
#include <cstring>
#include <boost/spirit/include/qi.hpp>
#define BOOST_SPIRIT_AUTO(domain_, name, expr) \
@ -34,21 +35,21 @@
boost::spirit::domain_::domain, name##_expr_type); \
BOOST_AUTO(name, boost::proto::deep_copy(expr)); \
#include <cmath> // log10
// karma is used by default unless
// the boost version is too old
#define MAPNIK_KARMA_TO_STRING
// boost
#include <boost/version.hpp>
#include <boost/math/special_functions/trunc.hpp> // trunc to avoid needing C++11
#if BOOST_VERSION >= 104500
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/karma.hpp>
#else
#include <boost/lexical_cast.hpp>
#ifdef MAPNIK_KARMA_TO_STRING
#include <boost/version.hpp>
#if BOOST_VERSION < 104500
#undef MAPNIK_KARMA_TO_STRING
#else
#include <boost/spirit/include/karma.hpp>
#include <cmath> // log10
#include <boost/math/special_functions/trunc.hpp> // trunc to avoid needing C++11
#endif
#endif
#include <cstring>
namespace mapnik {
namespace util {
@ -62,8 +63,6 @@ BOOST_SPIRIT_AUTO(qi, LONGLONG, qi::long_long)
BOOST_SPIRIT_AUTO(qi, FLOAT, qi::float_)
BOOST_SPIRIT_AUTO(qi, DOUBLE, qi::double_)
struct bool_symbols : qi::symbols<char,bool>
{
bool_symbols()
@ -163,7 +162,7 @@ bool string2float(const char * value, float & result)
return r && (iter == end);
}
#if BOOST_VERSION >= 104500
#ifdef MAPNIK_KARMA_TO_STRING
bool to_string(std::string & str, int value)
{
@ -286,48 +285,79 @@ bool to_string(std::string & str, double value)
#else
template <typename T>
bool to_string_lexical(std::string & str, T value)
bool to_string(std::string & s, int val)
{
try
s.resize(s.capacity());
while (true)
{
str = boost::lexical_cast<T>(value);
return true;
size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%d", val));
if (n2 <= s.size())
{
s.resize(n2);
break;
}
s.resize(n2);
}
catch (std::exception const& ex)
{
return false;
}
}
bool to_string(std::string & str, int value)
{
return to_string_lexical(str, value);
return true;
}
#ifdef BIGINT
bool to_string(std::string & str, mapnik::value_integer value)
bool to_string(std::string & s, mapnik::value_integer val)
{
return to_string_lexical(str, value);
s.resize(s.capacity());
while (true)
{
size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%lld", val));
if (n2 <= s.size())
{
s.resize(n2);
break;
}
s.resize(n2);
}
return true;
}
bool to_string(std::string & str, unsigned value)
{
return to_string_lexical(str, value);
}
bool to_string(std::string & str, bool value)
{
return to_string_lexical(str, value);
}
bool to_string(std::string & str, double value)
{
return to_string_lexical(str, value);
}
#endif
bool to_string(std::string & s, unsigned val)
{
s.resize(s.capacity());
while (true)
{
size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%u", val));
if (n2 <= s.size())
{
s.resize(n2);
break;
}
s.resize(n2);
}
return true;
}
bool to_string(std::string & s, bool val)
{
if (val) s = "true";
else s = "false";
return true;
}
bool to_string(std::string & s, double val)
{
s.resize(s.capacity());
while (true)
{
size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%g", val));
if (n2 <= s.size())
{
s.resize(n2);
break;
}
s.resize(n2);
}
return true;
}
#endif
} // end namespace util

View file

@ -24,9 +24,7 @@
#include <mapnik/markers_symbolizer.hpp>
#include <mapnik/value.hpp>
#include <mapnik/attribute.hpp>
// boost
#include <boost/make_shared.hpp>
#include <mapnik/parse_path.hpp>
namespace mapnik {

View file

@ -1,4 +1,5 @@
#include <boost/version.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/util/conversions.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <iostream>
@ -66,24 +67,107 @@ int main( int, char*[] )
to_string(out, double(0.0001234567890123456));
// TODO: https://github.com/mapnik/mapnik/issues/1676
//BOOST_TEST_EQ( out, "0.0001234567890123456" );
BOOST_TEST_EQ( out, "0.000123457" );
out.clear();
to_string(out, double(-0.0001234567890123456));
// TODO: https://github.com/mapnik/mapnik/issues/1676
//BOOST_TEST_EQ( out, "-0.0001234567890123456" );
to_string(out, double(0.0001));
BOOST_TEST_EQ( out, "0.0001" );
out.clear();
to_string(out, double(1000000000000000));
BOOST_TEST_EQ( out, "1000000000000000" );
to_string(out, double(0.00001));
BOOST_TEST_EQ( out, "1e-05" );
out.clear();
to_string(out, double(0.000001));
BOOST_TEST_EQ( out, "1e-06" );
out.clear();
to_string(out, double(0.0000001));
BOOST_TEST_EQ( out, "1e-07" );
out.clear();
to_string(out, double(0.00000001));
BOOST_TEST_EQ( out, "1e-08" );
out.clear();
to_string(out, double(0.000000001));
BOOST_TEST_EQ( out, "1e-09" );
out.clear();
to_string(out, double(0.0000000001));
BOOST_TEST_EQ( out, "1e-10" );
out.clear();
to_string(out, double(0.00000000001));
BOOST_TEST_EQ( out, "1e-11" );
out.clear();
to_string(out, double(0.000000000001));
BOOST_TEST_EQ( out, "1e-12" );
out.clear();
to_string(out, double(0.0000000000001));
BOOST_TEST_EQ( out, "1e-13" );
out.clear();
to_string(out, double(0.00000000000001));
BOOST_TEST_EQ( out, "1e-14" );
out.clear();
to_string(out, double(0.000000000000001));
BOOST_TEST_EQ( out, "1e-15" );
out.clear();
to_string(out, double(100000));
BOOST_TEST_EQ( out, "100000" );
out.clear();
to_string(out, double(1000000));
BOOST_TEST_EQ( out, "1e+06" );
out.clear();
to_string(out, double(10000000));
BOOST_TEST_EQ( out, "1e+07" );
out.clear();
to_string(out, double(100000000));
BOOST_TEST_EQ( out, "1e+08" );
out.clear();
to_string(out, double(1000000000));
BOOST_TEST_EQ( out, "1e+09" );
out.clear();
to_string(out, double(10000000000));
BOOST_TEST_EQ( out, "1e+10" );
out.clear();
to_string(out, double(100000000000));
BOOST_TEST_EQ( out, "1e+11" );
out.clear();
to_string(out, double(1000000000000));
BOOST_TEST_EQ( out, "1e+12" );
out.clear();
to_string(out, double(10000000000000));
BOOST_TEST_EQ( out, "1e+13" );
out.clear();
to_string(out, double(100000000000000));
BOOST_TEST_EQ( out, "1e+14" );
out.clear();
to_string(out, double(1000000000000005));
BOOST_TEST_EQ( out, "1e+15" );
out.clear();
to_string(out, double(-1000000000000000));
BOOST_TEST_EQ( out, "-1000000000000000" );
BOOST_TEST_EQ( out, "-1e+15" );
out.clear();
to_string(out, double(100000000000000.1));
BOOST_TEST_EQ( out, "100000000000000.1" );
BOOST_TEST_EQ( out, "1e+14" );
out.clear();
to_string(out, double(1.00001));
@ -91,7 +175,11 @@ int main( int, char*[] )
out.clear();
to_string(out, double(1234000000000000));
BOOST_TEST_EQ( out, "1234000000000000" );
BOOST_TEST_EQ( out, "1.234e+15" );
out.clear();
to_string(out, double(1e+16));
BOOST_TEST_EQ( out, "1e+16" );
out.clear();
to_string(out, double(1.234e+16));
@ -101,12 +189,59 @@ int main( int, char*[] )
to_string(out, double(-1.234e+16));
BOOST_TEST_EQ( out, "-1.234e+16" );
out.clear();
// https://github.com/mapbox/tilemill/issues/1456
to_string(out, double(8.3));
BOOST_TEST_EQ( out, "8.3" );
out.clear();
// Test int
to_string(out, int(2));
// int
to_string(out, int(2));
BOOST_TEST_EQ( out, "2" );
out.clear();
to_string(out, int(0));
BOOST_TEST_EQ( out, "0" );
out.clear();
to_string(out, int(-2));
BOOST_TEST_EQ( out, "-2" );
out.clear();
to_string(out, int(2147483647));
BOOST_TEST_EQ( out, "2147483647" );
out.clear();
to_string(out, int(-2147483648));
BOOST_TEST_EQ( out, "-2147483648" );
out.clear();
// unsigned
to_string(out, unsigned(4294967295));
BOOST_TEST_EQ( out, "4294967295" );
out.clear();
#ifdef BIGINT
// long long
to_string(out,mapnik::value_integer(-0));
BOOST_TEST_EQ( out, "0" );
out.clear();
to_string(out,mapnik::value_integer(-2));
BOOST_TEST_EQ( out, "-2" );
out.clear();
to_string(out,mapnik::value_integer(9223372036854775807));
BOOST_TEST_EQ( out, "9223372036854775807" );
out.clear();
#endif
// bool
to_string(out, true);
BOOST_TEST_EQ( out, "true" );
out.clear();
to_string(out, false);
BOOST_TEST_EQ( out, "false" );
out.clear();
}
catch (std::exception const & ex)
{

View file

@ -2,7 +2,7 @@
from nose.tools import *
import os,sys
from utilities import execution_path, run_tests, Todo
from utilities import execution_path, run_all, Todo
from utilities import get_unique_colors, pixel2channels, side_by_side_image
import mapnik
@ -254,9 +254,9 @@ def test_background_image_with_alpha_and_background_color_against_composited_con
im1.demultiply()
# compare image rendered (compositing in `agg_renderer<T>::setup`)
# vs image composited via python bindings
raise Todo("looks like we need to investigate PNG rounding when saving")
raise Todo("looks like we need to investigate PNG color rounding when saving")
eq_(get_unique_colors(im),get_unique_colors(im1))
if __name__ == "__main__":
setup()
run_tests(eval(x) for x in dir() if x.startswith("test_"))
run_all(eval(x) for x in dir() if x.startswith("test_"))

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python
from nose.tools import *
from utilities import execution_path, run_tests
from utilities import execution_path, run_all
from utilities import side_by_side_image
import os, mapnik
import re
@ -65,4 +65,4 @@ if 'shape' in mapnik.DatasourceCache.plugin_names():
if __name__ == "__main__":
setup()
run_tests(eval(x) for x in dir() if x.startswith("test_"))
run_all(eval(x) for x in dir() if x.startswith("test_"))

View file

@ -58,25 +58,24 @@ def get_unique_colors(im):
pixels = sorted(pixels)
return map(pixel2rgba,pixels)
def run_tests(iterable=None):
def run_all(iterable):
failed = 0
if iterable:
for test in iterable:
try:
test()
sys.stderr.write("\x1b[32m✓ \x1b[m" + test.__name__ + "\x1b[m\n")
except:
exc_type, exc_value, exc_tb = sys.exc_info()
failed += 1
sys.stderr.write("\x1b[31m✘ \x1b[m" + test.__name__ + "\x1b[m\n")
for mline in traceback.format_exception_only(exc_type, exc_value):
for line in mline.rstrip().split("\n"):
sys.stderr.write(" \x1b[31m" + line + "\x1b[m\n")
sys.stderr.write(" Traceback:\n")
for mline in traceback.format_tb(exc_tb):
for line in mline.rstrip().split("\n"):
sys.stderr.write(" " + line + "\n")
sys.stderr.flush()
for test in iterable:
try:
test()
sys.stderr.write("\x1b[32m✓ \x1b[m" + test.__name__ + "\x1b[m\n")
except:
exc_type, exc_value, exc_tb = sys.exc_info()
failed += 1
sys.stderr.write("\x1b[31m✘ \x1b[m" + test.__name__ + "\x1b[m\n")
for mline in traceback.format_exception_only(exc_type, exc_value):
for line in mline.rstrip().split("\n"):
sys.stderr.write(" \x1b[31m" + line + "\x1b[m\n")
sys.stderr.write(" Traceback:\n")
for mline in traceback.format_tb(exc_tb):
for line in mline.rstrip().split("\n"):
sys.stderr.write(" " + line + "\n")
sys.stderr.flush()
return failed
def side_by_side_image(left_im, right_im):