def test_complex_queries(): httpd1 = _HttpdConf(context_wrap(HTTPD_CONF_NEST_1, path='/etc/httpd/conf/httpd.conf')) httpd2 = _HttpdConf(context_wrap(HTTPD_CONF_NEST_3, path='/etc/httpd/conf.d/00-a.conf')) httpd3 = _HttpdConf(context_wrap(HTTPD_CONF_NEST_4, path='/etc/httpd/conf.d/01-b.conf')) result = HttpdConfTree([httpd1, httpd2, httpd3]) assert len(result.select("VirtualHost")) == 3 assert len(result.select(("VirtualHost", "128.39.140.28"))) == 2 assert len(result.select(("VirtualHost", "128.39.140.30"))) == 1 assert len(result.select(("VirtualHost", startswith("128.39.140")))) == 3 assert len(result.select(("VirtualHost", ~startswith("128.39.140")))) == 0 assert len(result.select(("VirtualHost", endswith("140.30")))) == 1 assert len(result.select(("VirtualHost", ~endswith("140.30")))) == 2 assert len(result.select((startswith("Virtual"), ~endswith("140.30")))) == 2 assert len(result.select("FilesMatch", deep=True, roots=False)) == 3 # find all IfModule !php5_module stanzas regardless of location assert len(result.select(("IfModule", "!php5_module"), deep=True, roots=False)) == 6 # find all IfModule !php5_module stanzas immediately beneath a VirtualHost assert len(result.select("VirtualHost", ("IfModule", "!php5_module"), roots=False)) == 3 # find all IfModule !php4_module stanzas anywhere beneath a top level VirtualHost res = result.select("VirtualHost").select(("IfModule", "!php4_module"), deep=True, roots=False) assert len(res) == 3 assert len(result.select(("VirtualHost", ~is_private))) == 3 res = result.select(("VirtualHost", in_network("128.39.0.0/16"))) assert len(res) == 3 res = result.select(("VirtualHost", ~is_private & in_network("128.39.0.0/16"))) assert len(res) == 3
def test_endswith(): data = ["abc", "abrd", "ed"] assert endswith("d")(data) assert endswith("d")("end") assert not endswith("re")(data)