zwoop commented on code in PR #13058: URL: https://github.com/apache/trafficserver/pull/13058#discussion_r3052739695
########## tools/hrw4u/tests/test_autest_rules.py: ########## @@ -0,0 +1,67 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Test hrw4u -> conf conversion matches the autest .conf files.""" +from __future__ import annotations + +from pathlib import Path + +import pytest +from antlr4 import CommonTokenStream, InputStream + +from hrw4u.hrw4uLexer import hrw4uLexer +from hrw4u.hrw4uParser import hrw4uParser +from hrw4u.visitor import HRW4UVisitor +from hrw4u.errors import ErrorCollector + +AUTEST_RULES_DIR = Path( + __file__).resolve().parent.parent.parent.parent / "tests" / "gold_tests" / "pluginTest" / "header_rewrite" / "rules" + + +def _collect_autest_pairs() -> list[pytest.param]: + """Collect .conf/.hrw4u pairs from the autest rules directory.""" + if not AUTEST_RULES_DIR.is_dir(): + return [] + + pairs = [] + for conf in sorted(AUTEST_RULES_DIR.glob("*.conf")): + hrw4u = conf.with_suffix(".hrw4u") + if hrw4u.exists(): + pairs.append(pytest.param(conf, hrw4u, id=conf.stem)) + + return pairs + + [email protected]("conf_file,hrw4u_file", _collect_autest_pairs()) +def test_hrw4u_to_conf(conf_file: Path, hrw4u_file: Path) -> None: + """Test that hrw4u -> conf output matches the .conf file.""" Review Comment: Added `@pytest.mark.autest` back. The marker doesn't filter by default, so tests still run in the normal suite, but can be selected with `-m autest`. ########## tools/hrw4u/tests/test_autest_rules_reverse.py: ########## @@ -0,0 +1,65 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Test conf -> hrw4u conversion matches the autest .hrw4u files.""" +from __future__ import annotations + +from pathlib import Path + +import pytest +from antlr4 import CommonTokenStream, InputStream + +from u4wrh.u4wrhLexer import u4wrhLexer +from u4wrh.u4wrhParser import u4wrhParser +from u4wrh.hrw_visitor import HRWInverseVisitor + +AUTEST_RULES_DIR = Path( + __file__).resolve().parent.parent.parent.parent / "tests" / "gold_tests" / "pluginTest" / "header_rewrite" / "rules" + + +def _collect_autest_pairs() -> list[pytest.param]: + """Collect .conf/.hrw4u pairs from the autest rules directory.""" + if not AUTEST_RULES_DIR.is_dir(): + return [] + + pairs = [] + for conf in sorted(AUTEST_RULES_DIR.glob("*.conf")): + hrw4u = conf.with_suffix(".hrw4u") + if hrw4u.exists(): + pairs.append(pytest.param(conf, hrw4u, id=conf.stem)) + + return pairs + + [email protected]("conf_file,hrw4u_file", _collect_autest_pairs()) +def test_conf_to_hrw4u(conf_file: Path, hrw4u_file: Path) -> None: + """Test that conf -> hrw4u output matches the .hrw4u file.""" Review Comment: Done — same fix applied here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
