From 761ce46ed98465132422835bd6c36c2ca1f708a9 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 15 Dec 2023 15:01:28 +0100 Subject: [PATCH 1/3] [ISSUE 123] complete unit tests for EC7 rule --- .../checks/AvoidGettersAndSettersTest.java | 3 ++- .../checks/avoidGettersAndSettersCompliant.py | 20 +++++++++++++++++++ ... => avoidGettersAndSettersNonCompliant.py} | 6 ++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/checks/avoidGettersAndSettersCompliant.py rename src/test/resources/checks/{avoidGettersAndSetters.py => avoidGettersAndSettersNonCompliant.py} (88%) diff --git a/src/test/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSettersTest.java b/src/test/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSettersTest.java index c68228e..91b124d 100644 --- a/src/test/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSettersTest.java +++ b/src/test/java/fr/greencodeinitiative/python/checks/AvoidGettersAndSettersTest.java @@ -24,6 +24,7 @@ public class AvoidGettersAndSettersTest { @Test public void test() { - PythonCheckVerifier.verify("src/test/resources/checks/avoidGettersAndSetters.py", new AvoidGettersAndSetters()); + PythonCheckVerifier.verifyNoIssue("src/test/resources/checks/avoidGettersAndSettersCompliant.py", new AvoidGettersAndSetters()); + PythonCheckVerifier.verify("src/test/resources/checks/avoidGettersAndSettersNonCompliant.py", new AvoidGettersAndSetters()); } } diff --git a/src/test/resources/checks/avoidGettersAndSettersCompliant.py b/src/test/resources/checks/avoidGettersAndSettersCompliant.py new file mode 100644 index 0000000..13fa802 --- /dev/null +++ b/src/test/resources/checks/avoidGettersAndSettersCompliant.py @@ -0,0 +1,20 @@ +from datetime import date + +class Client(): + + def __init__(self, age, weight): + self.age = age + self.weight = weight + + def get_age_in_five_years(self): + a = Client() + return a.age + + def is_major(self): + return self.age >= 18 + +client = Client(25) +client.age +client.age = 25 +client.weight +client.weight(5) \ No newline at end of file diff --git a/src/test/resources/checks/avoidGettersAndSetters.py b/src/test/resources/checks/avoidGettersAndSettersNonCompliant.py similarity index 88% rename from src/test/resources/checks/avoidGettersAndSetters.py rename to src/test/resources/checks/avoidGettersAndSettersNonCompliant.py index 538e79a..4506eb2 100644 --- a/src/test/resources/checks/avoidGettersAndSetters.py +++ b/src/test/resources/checks/avoidGettersAndSettersNonCompliant.py @@ -24,3 +24,9 @@ def is_major(self): def get_weight(self): # Noncompliant {{Avoid creating getter and setter methods in classes}} return self.weight + +client = Client(25) +client.get_age() +client.set_age(25) +client.get_weight() +client.set_weight(5) \ No newline at end of file From baef95a0f08a431fece1aecfc66f32cdf4d1e4a9 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 15 Dec 2023 15:18:44 +0100 Subject: [PATCH 2/3] [ISSUE 123] improve unit tests for EC7 rule - CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d27ed0..362d9a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#6](https://github.com/green-code-initiative/ecoCode-python/pull/6) Adding EC35 rule : EC35 rule replaces EC34 with a specific use case ("file not found" sepcific) - [#7](https://github.com/green-code-initiative/ecoCode-python/issues/7) Add build number to manifest - Update ecocode-rules-specifications to 0.0.9 +- [#123](https://github.com/green-code-initiative/ecoCode/issues/123) Imprive unit tests for EC7 rule ### Deleted From 2e86afbc6b77c4fbf4b0b77e32b1709eea47bcc1 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 15 Dec 2023 23:51:10 +0100 Subject: [PATCH 3/3] update ecocode-rules-spec to 0.0.10 --- CHANGELOG.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 362d9a0..79f2dbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,8 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#5](https://github.com/green-code-initiative/ecoCode-python/pull/5) Upgrade licence system and licence headers of Java files - [#6](https://github.com/green-code-initiative/ecoCode-python/pull/6) Adding EC35 rule : EC35 rule replaces EC34 with a specific use case ("file not found" sepcific) - [#7](https://github.com/green-code-initiative/ecoCode-python/issues/7) Add build number to manifest -- Update ecocode-rules-specifications to 0.0.9 - [#123](https://github.com/green-code-initiative/ecoCode/issues/123) Imprive unit tests for EC7 rule +- Update ecocode-rules-specifications to 0.0.10 ### Deleted diff --git a/pom.xml b/pom.xml index f158ee9..1c39fdb 100644 --- a/pom.xml +++ b/pom.xml @@ -59,7 +59,7 @@ 5.3.1 - 0.0.9 + 0.0.10 2.5.0.1358