def test(self): # run all available osmosis analysers, for basic SQL check import importlib import inspect import os for fn in os.listdir("analysers/"): if not fn.startswith("analyser_osmosis_") or not fn.endswith( ".py"): continue analyser = importlib.import_module("analysers." + fn[:-3], package=".") for name, obj in inspect.getmembers(analyser): if (inspect.isclass(obj) and obj.__module__ == ("analysers." + fn[:-3]) and (name.startswith("Analyser") or name.startswith("analyser"))): self.xml_res_file = self.default_xml_res_path + "normal/%s.xml" % name self.analyser_conf.error_file = IssuesFileOsmose.IssuesFileOsmose( self.xml_res_file) with obj(self.analyser_conf, self.logger) as analyser_obj: analyser_obj.analyser() self.root_err = self.load_errors() self.check_num_err(min=0, max=5)
def test_change_full(self): # run all available osmosis analysers, after marking all elements as new import importlib import inspect import os self.conf.osmosis_manager.set_pgsql_schema() for script in self.conf.osmosis_change_init_post_scripts: self.conf.osmosis_manager.psql_f(script) self.conf.osmosis_manager.psql_c("TRUNCATE TABLE actions;" "INSERT INTO actions (SELECT 'R', 'C', id FROM relations);" "INSERT INTO actions (SELECT 'W', 'C', id FROM ways);" "INSERT INTO actions (SELECT 'N', 'C', id FROM nodes);") for script in self.conf.osmosis_change_post_scripts: self.conf.osmosis_manager.psql_f(script) for fn in os.listdir("analysers/"): if not fn.startswith("analyser_osmosis_") or not fn.endswith(".py"): continue analyser = importlib.import_module("analysers." + fn[:-3], package=".") for name, obj in inspect.getmembers(analyser): if (inspect.isclass(obj) and obj.__module__ == ("analysers." + fn[:-3]) and (name.startswith("Analyser") or name.startswith("analyser"))): self.xml_res_file = self.default_xml_res_path + "diff_full/{0}.xml".format(name) self.analyser_conf.error_file = IssuesFileOsmose.IssuesFileOsmose(self.xml_res_file) with obj(self.analyser_conf, self.logger) as analyser_obj: analyser_obj.analyser_change() self.root_err = self.load_errors() self.check_num_err(min=0, max=5)
def test_change_empty(self): # run all available osmosis analysers, for basic SQL check import importlib import inspect import os self.conf.osmosis_manager.set_pgsql_schema() for script in self.conf.osmosis_change_init_post_scripts: self.conf.osmosis_manager.psql_f(script) self.conf.osmosis_manager.psql_c("TRUNCATE TABLE actions") for script in self.conf.osmosis_change_post_scripts: self.conf.osmosis_manager.psql_f(script) for fn in os.listdir("analysers/"): if not fn.startswith("analyser_osmosis_") or not fn.endswith(".py"): continue analyser = importlib.import_module("analysers." + fn[:-3], package=".") for name, obj in inspect.getmembers(analyser): if (inspect.isclass(obj) and obj.__module__ == ("analysers." + fn[:-3]) and (name.startswith("Analyser") or name.startswith("analyser"))): self.xml_res_file = self.default_xml_res_path + "diff_empty/{0}.xml".format(name) self.analyser_conf.error_file = IssuesFileOsmose.IssuesFileOsmose(self.xml_res_file) with obj(self.analyser_conf, self.logger) as analyser_obj: analyser_obj.analyser_change() self.root_err = self.load_errors() self.check_num_err(min=0, max=5)
def test_fr_nl(self): self.xml_res_file = os.path.join(self.dirname, "sax.test.Lang_fr_nl.xml") self.config.error_file = IssuesFileOsmose.IssuesFileOsmose(self.xml_res_file) self.config.options = {"language": ["fr", "nl"], "project": "openstreetmap"} with Analyser_Sax(self.config) as analyser_obj: analyser_obj.analyser() self.compare_results("tests/results/sax.test.Lang_fr_nl.xml") self.root_err = self.load_errors() self.check_num_err(min=34)
def test_FR(self): self.xml_res_file = os.path.join(self.dirname, "sax.test.FR.xml") self.config.error_file = IssuesFileOsmose.IssuesFileOsmose(self.xml_res_file) self.config.options = {"country": "FR", "project": "openstreetmap"} with Analyser_Sax(self.config) as analyser_obj: analyser_obj.analyser() self.compare_results("tests/results/sax.test.FR.xml") self.root_err = self.load_errors() self.check_num_err(min=47)
def test_resume(self): self.xml_res_file = os.path.join(self.dirname, "sax.test_resume.xml") self.config.error_file = IssuesFileOsmose.IssuesFileOsmose(self.xml_res_file) self.config.options = {"project": "openstreetmap"} with Analyser_Sax(self.config) as analyser_obj: analyser_obj.analyser_resume(dateutil.parser.parse("2012-07-18T11:04:56Z").replace(tzinfo=None), {'N': set([1]), 'W': set([24552698]), 'R': set()}) self.compare_results("tests/results/sax.test_resume.xml") self.root_err = self.load_errors() self.check_num_err(min=11)
def test_resume_empty(self): # Test with an younger timestamp than youngest object in extract self.xml_res_file = os.path.join(self.dirname, "sax.test_resume_empty.xml") self.config.error_file = IssuesFileOsmose.IssuesFileOsmose(self.xml_res_file) self.config.options = {"project": "openstreetmap"} with Analyser_Sax(self.config) as analyser_obj: analyser_obj.analyser_resume(dateutil.parser.parse("2030-01-01T01:01:01Z").replace(tzinfo=None), {'N': set([1]), 'W': set([1000,1001]), 'R': set()}) self.compare_results("tests/results/sax.test_resume_empty.xml") self.root_err = self.load_errors() self.check_num_err(min=0, max=0)
def test_resume_full(self): # Test with an older timestamp than older object in extract self.xml_res_file = os.path.join(self.dirname, "sax.test_resume_full.xml") self.config.error_file = IssuesFileOsmose.IssuesFileOsmose(self.xml_res_file) self.config.options = {"project": "openstreetmap"} with Analyser_Sax(self.config) as analyser_obj: analyser_obj.analyser_resume("2000-01-01T01:01:01Z", {'N': set(), 'W': set(), 'R': set()}) self.compare_results("tests/results/sax.test_resume_full.xml") self.root_err = self.load_errors() self.check_num_err(min=13)
def init_config(osm_file=None, dst=None, analyser_options=None): import os import osmose_run import osmose_config conf = osmose_config.template_config("test", analyser_options=analyser_options) conf.db_host = os.environ.get('DB_HOST', 'localhost') conf.db_base = os.environ.get('DB_BASE_TEST', 'osmose_test') conf.db_schema = conf.country conf.download["dst"] = osm_file conf.init() class options: plugin = None verbose = False change = False analyser_conf = osmose_run.analyser_config(conf, options(), None) analyser_conf.error_file = IssuesFileOsmose.IssuesFileOsmose(dst) return (conf, analyser_conf)
class config: options = {"country": "FR", "language": "fr"} src = sys.argv[1] error_file = IssuesFileOsmose.IssuesFileOsmose(sys.argv[2])