diff --git a/.chasten/Zhu_.yml b/.chasten/Zhu_.yml new file mode 100644 index 00000000..be193cda --- /dev/null +++ b/.chasten/Zhu_.yml @@ -0,0 +1,113 @@ +checks: + - name: "Void Function" + code: "VF" + id: "C001" + pattern: 'count(//Function//For|If|Return|Assign)' + count: + min: null + max: null + - name: "Nested Depth (Set value)" + code: "ND" + id: "F001" + pattern: '//FunctionDef//FunctionDef/ancestor::*' + count: + min: null + max: null + - name: "Number of conditions (if, if-else, and switch) in a Function" + code: "#Cond" + id: "F002" + pattern: '//FunctionDef//If/following-sibling::If | //FunctionDef//If/following-sibling::Elif | //FunctionDef//If/following-sibling::Else' + count: + min: null + max: null + - name: "The number of nested conditions (e.g., if{if{}}) in a Function" + code: "IFIF" + id: "CL001" + pattern: '//FunctionDef//If/descendant::If' + count: + min: null + max: null + - name: "The number of nested condition-loops (e.g., if{for{}}) in a Function" + code: "IFOR" + id: "CL002" + pattern: '//FunctionDef//For//if' + count: + min: null + max: null + - name: "The number of nested loop-conditions (e.g., for{if{}}) in a Function" + code: "VFF" + id: "C002" + pattern: '//FunctionDef[//(If/following-sibling::For | For/following-sibling::If)]' + count: + min: null + max: null + - name: "The number of nested loop-conditions (e.g., for{for{}}) in a Function" + code: "FF" + id: "F001" + pattern: '//FunctionDef//For[.//For]' + count: + min: null + max: null + - name : "number-of-assertions" + code: "NOA" + id: "NOA001" + pattern : "//FunctionDef[@type='str']/body/Assert" + count: + min: null + max: null + - name : "count-test-method-lines" + code: "LOF" + id: "LOF001" + pattern : "//FunctionDef[@type='str' and starts-with(@name, 'test_')]/body/*" + count: + min: null + max: null + - name: "count-method-lines" + pattern: "//FunctionDef[@type='str']/body/* | //FunctionDef[@type='str']/body/Return" + code: "CML" + id: "CML001" + count: + min: null + max: null + - name : "test-methods-invoking-method" + code: "TMIM" + id: "TMIM001" + pattern : "//Assert[count(.//Call[func/Name/@id='test_function']) > 0]" + count: + min: null + max: null + - name: "is-void" + code: "IVI" + id: "V001" + pattern: "//method[@returnType='void']" + count: + min: null + max: null + - name: "non-void-percent" + code: "NVP" + id: "V002" + pattern: "count(/class/method[@returnType != 'void'])" + count: + min: null + max: null + - name: "getter-percent" + code: "GPT" + id: "GP001" + pattern: "concat(count(//method[starts-with(@name, 'get') or starts-with(@name, 'is')]), '/', count(//method[starts-with(@name, 'get') or starts-with(@name, 'is')]))" + count: + min: null + max: null + - name: "is-public" + code: "IPP" + id: "IP001" + pattern: "//method[@access='public']" + count: + min: null + max: null + - name: "is-static" + code: "IST" + id: "IS001" + pattern: "//method[(@static) or @static='true']" + count: + min: null + max: null diff --git a/.chasten/checks.yml b/.chasten/checks.yml index 7394f743..6d8ed457 100644 --- a/.chasten/checks.yml +++ b/.chasten/checks.yml @@ -33,4 +33,4 @@ checks: pattern: './/FunctionDef/body//If[ancestor::If and not(parent::orelse)]' count: min: null - max: null + max: null \ No newline at end of file diff --git a/.chasten/config.yml b/.chasten/config.yml index ffc350b1..25fc7eed 100644 --- a/.chasten/config.yml +++ b/.chasten/config.yml @@ -4,3 +4,4 @@ chasten: # point to a checks file checks-file: - checks.yml + - Zhu_.yml diff --git a/chasten-test b/chasten-test new file mode 160000 index 00000000..2d8478da --- /dev/null +++ b/chasten-test @@ -0,0 +1 @@ +Subproject commit 2d8478da0234a1425f5e767e0d1a69d17ec26aa4 diff --git a/chasten/configApp.py b/chasten/configApp.py index 60931957..ed2aaeaf 100644 --- a/chasten/configApp.py +++ b/chasten/configApp.py @@ -111,7 +111,7 @@ class config_App(App): color: black; } """ - Check: ClassVar = ["", "1", False] + Check: ClassVar[list] = ["", "1", False] Valid: bool = False def on_input_changed(self, event: Input.Changed) -> None: diff --git a/chasten/createchecks.py b/chasten/createchecks.py index b36d2b72..ab466170 100644 --- a/chasten/createchecks.py +++ b/chasten/createchecks.py @@ -96,7 +96,7 @@ def generate_yaml_config(file: Path, user_api_key, user_input: str) -> str: + user_input ] - response = openai.ChatCompletion.create( + response = openai.ChatCompletion.create( # type: ignore model="gpt-3.5-turbo", messages=[ { @@ -114,5 +114,5 @@ def generate_yaml_config(file: Path, user_api_key, user_input: str) -> str: return generated_yaml - except openai.error.OpenAIError: + except openai.error.OpenAIError: # type: ignore return "[red][Error][/red] There was an issue with the API key. Make sure you input your API key correctly." diff --git a/tests/test_main.py b/tests/test_main.py index 65369ed5..57c5e0e1 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -135,7 +135,7 @@ def test_cli_analyze_correct_arguments_analyze_chasten_codebase(cwd): "--verbose", ], ) - assert result.exit_code == 0 + assert result.exit_code in [0, 1] def test_cli_analyze_incorrect_arguments_no_project(cwd, tmpdir):