From cc96a3225e2bd07320104235443be2243fc03344 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sun, 29 May 2022 00:50:20 +0800 Subject: [PATCH] refactor: rename debugtalk_gen.py to .debugtalk_gen.py --- examples/demo-empty-project/proj.json | 2 +- examples/demo-with-go-plugin/proj.json | 2 +- .../{debugtalk_gen.py => .debugtalk_gen.py} | 0 examples/demo-with-py-plugin/proj.json | 2 +- examples/demo-without-plugin/proj.json | 2 +- hrp/internal/build/main.go | 2 +- hrp/internal/build/main_test.go | 6 +- .../debugtalk_gen.py => .debugtalk_gen.py} | 0 .../templates/plugin/.debugtalk_gen.py | 75 +++++++++++++++++++ hrp/plugin.go | 11 ++- hrp/runner_test.go | 4 +- 11 files changed, 90 insertions(+), 16 deletions(-) rename examples/demo-with-py-plugin/{debugtalk_gen.py => .debugtalk_gen.py} (100%) rename hrp/internal/scaffold/templates/{plugin/debugtalk_gen.py => .debugtalk_gen.py} (100%) create mode 100644 hrp/internal/scaffold/templates/plugin/.debugtalk_gen.py diff --git a/examples/demo-empty-project/proj.json b/examples/demo-empty-project/proj.json index 4e27d6b1..2eac429f 100644 --- a/examples/demo-empty-project/proj.json +++ b/examples/demo-empty-project/proj.json @@ -1,6 +1,6 @@ { "project_name": "demo-empty-project", "project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-empty-project", - "create_time": "2022-05-29T00:19:34.824392+08:00", + "create_time": "2022-05-29T00:38:43.685282+08:00", "hrp_version": "v4.1.0" } \ No newline at end of file diff --git a/examples/demo-with-go-plugin/proj.json b/examples/demo-with-go-plugin/proj.json index 47fd0ada..b5665891 100644 --- a/examples/demo-with-go-plugin/proj.json +++ b/examples/demo-with-go-plugin/proj.json @@ -1,6 +1,6 @@ { "project_name": "demo-with-go-plugin", "project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-with-go-plugin", - "create_time": "2022-05-29T00:19:33.056663+08:00", + "create_time": "2022-05-29T00:38:42.384694+08:00", "hrp_version": "v4.1.0" } \ No newline at end of file diff --git a/examples/demo-with-py-plugin/debugtalk_gen.py b/examples/demo-with-py-plugin/.debugtalk_gen.py similarity index 100% rename from examples/demo-with-py-plugin/debugtalk_gen.py rename to examples/demo-with-py-plugin/.debugtalk_gen.py diff --git a/examples/demo-with-py-plugin/proj.json b/examples/demo-with-py-plugin/proj.json index 1c2f45d3..8dba7a24 100644 --- a/examples/demo-with-py-plugin/proj.json +++ b/examples/demo-with-py-plugin/proj.json @@ -1,6 +1,6 @@ { "project_name": "demo-with-py-plugin", "project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-with-py-plugin", - "create_time": "2022-05-29T00:19:33.203339+08:00", + "create_time": "2022-05-29T00:38:42.523325+08:00", "hrp_version": "v4.1.0" } \ No newline at end of file diff --git a/examples/demo-without-plugin/proj.json b/examples/demo-without-plugin/proj.json index dc1bc258..6aafc4c4 100644 --- a/examples/demo-without-plugin/proj.json +++ b/examples/demo-without-plugin/proj.json @@ -1,6 +1,6 @@ { "project_name": "demo-without-plugin", "project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-without-plugin", - "create_time": "2022-05-29T00:19:34.698757+08:00", + "create_time": "2022-05-29T00:38:43.556711+08:00", "hrp_version": "v4.1.0" } \ No newline at end of file diff --git a/hrp/internal/build/main.go b/hrp/internal/build/main.go index 6e7902f6..45d1912e 100644 --- a/hrp/internal/build/main.go +++ b/hrp/internal/build/main.go @@ -32,7 +32,7 @@ const ( const ( genDebugTalkGo = "debugtalk_gen.go" - genDebugTalkPy = "debugtalk_gen.py" + genDebugTalkPy = ".debugtalk_gen.py" ) //go:embed templates/debugtalkPythonTemplate diff --git a/hrp/internal/build/main_test.go b/hrp/internal/build/main_test.go index cfe1cdbf..b05fd53e 100644 --- a/hrp/internal/build/main_test.go +++ b/hrp/internal/build/main_test.go @@ -15,13 +15,13 @@ func TestRun(t *testing.T) { t.Fatal() } - genDebugTalkPy := "../scaffold/templates/plugin/debugtalk_gen.py" - err = Run("../scaffold/templates/plugin/debugtalk.py", genDebugTalkPy) + genDebugTalkPyPath := "../scaffold/templates/plugin/" + genDebugTalkPy + err = Run("../scaffold/templates/plugin/debugtalk.py", genDebugTalkPyPath) if !assert.Nil(t, err) { t.Fatal() } - contentBytes, err := builtin.ReadFile(genDebugTalkPy) + contentBytes, err := builtin.ReadFile(genDebugTalkPyPath) if !assert.Nil(t, err) { t.Fatal() } diff --git a/hrp/internal/scaffold/templates/plugin/debugtalk_gen.py b/hrp/internal/scaffold/templates/.debugtalk_gen.py similarity index 100% rename from hrp/internal/scaffold/templates/plugin/debugtalk_gen.py rename to hrp/internal/scaffold/templates/.debugtalk_gen.py diff --git a/hrp/internal/scaffold/templates/plugin/.debugtalk_gen.py b/hrp/internal/scaffold/templates/plugin/.debugtalk_gen.py new file mode 100644 index 00000000..1bc989f2 --- /dev/null +++ b/hrp/internal/scaffold/templates/plugin/.debugtalk_gen.py @@ -0,0 +1,75 @@ +# NOTE: Generated By hrp v4.1.0, DO NOT EDIT! + +import logging +import time +import funppy + +from typing import List + + +def get_user_agent(): + return "hrp/funppy" + + +def sleep(n_secs): + time.sleep(n_secs) + + +def sum(*args): + result = 0 + for arg in args: + result += arg + return result + + +def sum_ints(*args: List[int]) -> int: + result = 0 + for arg in args: + result += arg + return result + + +def sum_two_int(a: int, b: int) -> int: + return a + b + + +def sum_two_string(a: str, b: str) -> str: + return a + b + + +def sum_strings(*args: List[str]) -> str: + result = "" + for arg in args: + result += arg + return result + + +def concatenate(*args: List[str]) -> str: + result = "" + for arg in args: + result += str(arg) + return result + + +def setup_hook_example(name): + logging.warning("setup_hook_example") + return f"setup_hook_example: {name}" + + +def teardown_hook_example(name): + logging.warning("teardown_hook_example") + return f"teardown_hook_example: {name}" + + +if __name__ == "__main__": + funppy.register("get_user_agent", get_user_agent) + funppy.register("sleep", sleep) + funppy.register("sum", sum) + funppy.register("sum_ints", sum_ints) + funppy.register("sum_two_int", sum_two_int) + funppy.register("sum_two_string", sum_two_string) + funppy.register("sum_strings", sum_strings) + funppy.register("concatenate", concatenate) + funppy.register("setup_hook_example", setup_hook_example) + funppy.register("teardown_hook_example", teardown_hook_example) + funppy.serve() diff --git a/hrp/plugin.go b/hrp/plugin.go index 7d546c5f..952fbe9c 100644 --- a/hrp/plugin.go +++ b/hrp/plugin.go @@ -15,11 +15,11 @@ import ( ) const ( - goPluginFile = "debugtalk.so" // built from go plugin - hashicorpGoPluginFile = "debugtalk.bin" // built from hashicorp go plugin - hashicorpPyPluginFile = "debugtalk_gen.py" // used for hashicorp python plugin, automatically generated by HRP - debugtalkPyFile = "debugtalk.py" // write by user - projectInfoFile = "proj.json" // used for ensuring root project + goPluginFile = "debugtalk.so" // built from go plugin + hashicorpGoPluginFile = "debugtalk.bin" // built from hashicorp go plugin + hashicorpPyPluginFile = ".debugtalk_gen.py" // used for hashicorp python plugin, automatically generated by HRP + debugtalkPyFile = "debugtalk.py" // write by user + projectInfoFile = "proj.json" // used for ensuring root project ) func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, pluginDir string, err error) { @@ -73,7 +73,6 @@ func locatePlugin(path string) (pluginPath string, err error) { pluginPath, err = locateFile(path, debugtalkPyFile) if err == nil { - // convert debugtalk.py to debugtalk_gen.py // register funppy plugin genPyPluginPath := filepath.Join(filepath.Dir(pluginPath), hashicorpPyPluginFile) err = build.Run(pluginPath, genPyPluginPath) diff --git a/hrp/runner_test.go b/hrp/runner_test.go index 5a1327e2..7437c8bc 100644 --- a/hrp/runner_test.go +++ b/hrp/runner_test.go @@ -38,8 +38,8 @@ func buildHashicorpPyPlugin() { func removeHashicorpPyPlugin() { log.Info().Msg("[teardown] remove hashicorp python plugin") - // on v4.1^, running case will generate debugtalk_gen.py used by python plugin - os.Remove(templatesDir + "debugtalk_gen.py") + // on v4.1^, running case will generate .debugtalk_gen.py used by python plugin + os.Remove(templatesDir + hashicorpPyPluginFile) } func TestRunCaseWithGoPlugin(t *testing.T) {