This is an automated email from the ASF dual-hosted git repository.

sbp pushed a commit to branch sbp
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git


The following commit(s) were added to refs/heads/sbp by this push:
     new 4d446395 Add unit tests for classification
4d446395 is described below

commit 4d446395b8456f824fe7d0a13f2ce86de132e355
Author: Sean B. Palmer <[email protected]>
AuthorDate: Sun Mar 15 18:01:26 2026 +0000

    Add unit tests for classification
---
 tests/unit/test_classify.py | 94 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/tests/unit/test_classify.py b/tests/unit/test_classify.py
new file mode 100644
index 00000000..2bd61455
--- /dev/null
+++ b/tests/unit/test_classify.py
@@ -0,0 +1,94 @@
+# 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.
+
+import pathlib
+
+import atr.classify as classify
+
+
+def test_binary_matcher_classifies_as_binary(tmp_path):
+    path = pathlib.Path("maven-mvnd-1.0.4-windows-amd64.zip")
+    result = classify.classify(path, base_path=tmp_path, 
binary_matcher=_matches_windows)
+    assert result == classify.FileType.BINARY
+
+
+def test_binary_matcher_does_not_override_source_matcher(tmp_path):
+    path = pathlib.Path("apache-widget-1.0.tar.gz")
+    result = classify.classify(path, base_path=tmp_path, 
source_matcher=_always_true, binary_matcher=_always_true)
+    assert result == classify.FileType.SOURCE
+
+
+def test_binary_matcher_wins_over_stem_heuristic(tmp_path):
+    path = pathlib.Path("apache-widget-1.0-src.tar.gz")
+    result = classify.classify(path, base_path=tmp_path, 
binary_matcher=_always_true)
+    assert result == classify.FileType.BINARY
+
+
+def test_binary_stem_heuristic():
+    path = pathlib.Path("apache-widget-1.0-binary.zip")
+    assert classify.classify(path) == classify.FileType.BINARY
+
+
+def test_disallowed_files_detected():
+    path = pathlib.Path(".DS_Store")
+    assert classify.classify(path) == classify.FileType.DISALLOWED
+
+
+def test_matchers_from_policy_builds_both(tmp_path):
+    source_matcher, binary_matcher = 
classify.matchers_from_policy(["*-src.*"], ["*-bin.*"], tmp_path)
+    assert source_matcher is not None
+    assert binary_matcher is not None
+
+
+def test_matchers_from_policy_empty(tmp_path):
+    source_matcher, binary_matcher = classify.matchers_from_policy([], [], 
tmp_path)
+    assert source_matcher is None
+    assert binary_matcher is None
+
+
+def test_metadata_suffix_detected():
+    path = pathlib.Path("apache-widget-1.0.tar.gz.sha512")
+    assert classify.classify(path) == classify.FileType.METADATA
+
+
+def test_source_matcher_wins_over_stem_binary(tmp_path):
+    path = pathlib.Path("apache-widget-1.0-bin.tar.gz")
+    result = classify.classify(path, base_path=tmp_path, 
source_matcher=_always_true)
+    assert result == classify.FileType.SOURCE
+
+
+def test_source_stem_heuristic():
+    path = pathlib.Path("apache-widget-1.0-source.tar.gz")
+    assert classify.classify(path) == classify.FileType.SOURCE
+
+
+def test_stem_heuristics_are_fallback_after_policy(tmp_path):
+    path = pathlib.Path("apache-widget-1.0-src.tar.gz")
+    result = classify.classify(path, base_path=tmp_path, 
source_matcher=_always_false, binary_matcher=_always_false)
+    assert result == classify.FileType.SOURCE
+
+
+def _always_false(_path: str) -> bool:
+    return False
+
+
+def _always_true(_path: str) -> bool:
+    return True
+
+
+def _matches_windows(path: str) -> bool:
+    return "windows" in path


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to