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

xuanwo pushed a commit to branch planner
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git

commit 7e7baacd593640100574e33cff38495492d95fe7
Author: Xuanwo <[email protected]>
AuthorDate: Wed Oct 18 15:30:09 2023 +0800

    Refactor python
    
    Signed-off-by: Xuanwo <[email protected]>
---
 .github/scripts/__init__.py                | 17 ++++++++++++
 .github/scripts/behavior_test_plan.py      | 22 ++++++++++++---
 .github/scripts/test_behavior_test_plan.py | 43 ++++++++++++++++++++++++++++++
 .gitignore                                 |  3 +++
 4 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/.github/scripts/__init__.py b/.github/scripts/__init__.py
new file mode 100644
index 000000000..dae607cde
--- /dev/null
+++ b/.github/scripts/__init__.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python3
+# 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.
diff --git a/.github/scripts/behavior_test_plan.py 
b/.github/scripts/behavior_test_plan.py
index 534c68ae5..65fe55ef8 100755
--- a/.github/scripts/behavior_test_plan.py
+++ b/.github/scripts/behavior_test_plan.py
@@ -21,9 +21,21 @@ import json
 import os
 from pathlib import Path
 
+# The path for current script.
+SCRIPT_PATH = Path(__file__).parent.absolute()
+print(f"SCRIPT_PATH: {SCRIPT_PATH}")
+
+# The path for `.github` dir.
+GITHUB_DIR = SCRIPT_PATH.parent
+print(f"GITHUB_DIR: {GITHUB_DIR}")
+
+# The project dir for opendal.
+PROJECT_DIR = GITHUB_DIR.parent
+print(f"PROJECT_DIR: {PROJECT_DIR}")
+
 
 def get_provided_cases():
-    root_dir = ".github/services"
+    root_dir = f"{GITHUB_DIR}/services"
 
     cases = [
         {
@@ -62,7 +74,9 @@ def calculate_core_cases(cases, changed_files):
 
     # If any of the core files changed, we will run all cases.
     if any(
-        p.startswith("core/src/") and not p.startswith("core/src/services")
+        p.startswith("core/")
+        and not p.startswith("core/src/services/")
+        and not p.endswith(".md")
         for p in changed_files
     ):
         return cases
@@ -108,7 +122,7 @@ def plan(changed_files):
                 }
             )
 
-    return json.dumps(jobs)
+    return jobs
 
 
 # For quick test:
@@ -117,4 +131,4 @@ def plan(changed_files):
 if __name__ == "__main__":
     changed_files = sys.argv[1:]
     result = plan(changed_files)
-    print(result)
+    print(json.dumps(result))
diff --git a/.github/scripts/test_behavior_test_plan.py 
b/.github/scripts/test_behavior_test_plan.py
new file mode 100644
index 000000000..5f2a662b0
--- /dev/null
+++ b/.github/scripts/test_behavior_test_plan.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+# 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 unittest
+from behavior_test_plan import plan
+
+
+class BehaviorTestPlan(unittest.TestCase):
+    def test_empty(self):
+        result = plan([])
+        self.assertEqual(result, {})
+
+    def test_core_cargo_toml(self):
+        result = plan(["core/Cargo.toml"])
+        self.assertTrue(result["components"]["core"])
+
+    def test_core_services_fs(self):
+        result = plan(["core/src/services/fs/mod.rs"])
+        self.assertTrue(result["components"]["core"])
+        self.assertTrue(len(result["core"]) > 0)
+        # Should not contain fs
+        self.assertTrue("services-fs" in result["core"][0]["features"])
+        # Should not contain s3
+        self.assertFalse("services-s3" in result["core"][0]["features"])
+
+
+if __name__ == "__main__":
+    unittest.main()
diff --git a/.gitignore b/.gitignore
index d5fd6da84..dc9a92312 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,3 +18,6 @@ perf.*
 
 # Yarn Integrity file
 .yarn-integrity
+
+# Python cache files
+**/__pycache__/

Reply via email to