From 83cf6148cd043e01e1c12747ab47989c74ff21c9 Mon Sep 17 00:00:00 2001 From: Farshad Date: Mon, 19 Oct 2020 10:34:22 -0400 Subject: [PATCH 1/3] added support for LIST remove_item and remove_at commands, LIST insert test is also added so that we add support for that later --- .gitignore | 3 ++- datastructs.py | 20 ++++++++++++++++ test/result.json | 8 +++++++ test/result.pkl | Bin 0 -> 185 bytes test/variable_test.py | 52 +++++++++++++++++++++++++++++++++++++++++- 5 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 test/result.json create mode 100644 test/result.pkl diff --git a/.gitignore b/.gitignore index 97e58fcc..8e31853b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ __pycache__/ graph.gv graph.gv.pdf *.log -.venv \ No newline at end of file +.venv +venv diff --git a/datastructs.py b/datastructs.py index 06148598..4ca5c50a 100644 --- a/datastructs.py +++ b/datastructs.py @@ -353,6 +353,26 @@ def evaluate(self, conditions, recStack, lookup=None): recStack=recStack) return result + if 'remove_item' in self.getName().lower(): + print("hello!") + arguments = flattenAlgorithmWithConditions(self.commands[0].getChildren(),conditions, recStack=recStack) + result = flattenAlgorithmWithConditions(self.depends[0],conditions, recStack=recStack) + for argument in arguments: + for item in result: + if item[0] == argument.getValue(): + result=[i for i in result if i != item] + print('result',result) + return result; + + if 'remove_at' in self.getName().lower(): + arguments = self.commands[0].getChildren() + result = flattenAlgorithmWithConditions(self.depends[0],conditions, recStack=recStack) + for argument in arguments: + del result[argument.getValue()] + return result; + + + class ConcatNode(Node): def __init__(self, name: str): diff --git a/test/result.json b/test/result.json new file mode 100644 index 00000000..45577c97 --- /dev/null +++ b/test/result.json @@ -0,0 +1,8 @@ +{ + "BUILD_SERVER:True && FEATURE_IRC_SERVER:True": [ + "files_for_test/b.cxx" + ], + "NO_MATTER_WHAT": [ + "files_for_test/a.cxx" + ] +} \ No newline at end of file diff --git a/test/result.pkl b/test/result.pkl new file mode 100644 index 0000000000000000000000000000000000000000..f7a0e6455cd78b728b48b367a2d47dcdc4a092fd GIT binary patch literal 185 zcmZo*nYxYv0(!WU^K)`ilS?x5^NOeRaHpiEC6?xtq+}+SOqo2Tha;&pGp8gIB*k2u z3KD9a5;R4lN5?7D)5j$~*fl83HOMNYs5DhUO-;eg)iESA$Ti+G$QfB`Ne187%zK$Uwu0iqP9*!Yc)h0sJmg)fj1eHUJ literal 0 HcmV?d00001 diff --git a/test/variable_test.py b/test/variable_test.py index 8da0244f..e0ecdf3e 100644 --- a/test/variable_test.py +++ b/test/variable_test.py @@ -1874,7 +1874,7 @@ def test_list_remove_variable(self): list(REMOVE_ITEM foo b) """ self.runTool(text) - # self.vmodel.export() + self.vmodel.export() def test_variable_growth(self): text = """ @@ -1913,5 +1913,55 @@ def test_sample_1(self): """ self.runTool(text) + + def test_conditional_list_remove_variable(self): + text = """ + option(opt1 "des1" YES) + set(foo john doe bar) + if(opt1) + list(REMOVE_ITEM foo john boo) + endif() + """ + self.runTool(text) + var = self.lookup.getKey('${foo}') + a = flattenAlgorithmWithConditions(var) + self.vmodel.export() + + def test_complex_conditional_list_remove_variable(self): + text = """ + option(opt1 "des" YES) + option(opt2 "des" YES) + + set(var_a foo bar john doe) + if(opt1) + list(REMOVE_ITEM var_a bar Farshad) + elseif(opt2) + list(REMOVE_ITEM var_a john Mehran) + endif() + """ + self.runTool(text) + self.vmodel.export() + + + def test_remove_at_conditional_list_remove_variable(self): + text = """ + set(var_a foo bar john doe) + set(item 2) + list(REMOVE_AT var_a ${item}) + """ + self.runTool(text) + self.vmodel.export() + + + def test_insert_list_remove_variable(self): + # TODO: need implementation + text = """ + set(var_a foo bar john doe) + set(item foo) + list(INSERT var_a ${item}) + """ + self.runTool(text) + self.vmodel.export() + if __name__ == '__main__': unittest.main() From 0ccb38561145190d74c5652c921776a37b425bd6 Mon Sep 17 00:00:00 2001 From: Mehran Meidani Date: Mon, 19 Oct 2020 13:06:47 -0400 Subject: [PATCH 2/3] Delete result.json --- test/result.json | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 test/result.json diff --git a/test/result.json b/test/result.json deleted file mode 100644 index 45577c97..00000000 --- a/test/result.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "BUILD_SERVER:True && FEATURE_IRC_SERVER:True": [ - "files_for_test/b.cxx" - ], - "NO_MATTER_WHAT": [ - "files_for_test/a.cxx" - ] -} \ No newline at end of file From c26cba9c232c50e21f29182e9573f53b56eced50 Mon Sep 17 00:00:00 2001 From: Farshad Date: Wed, 28 Oct 2020 10:32:01 -0400 Subject: [PATCH 3/3] fixed test cases, added support for conditions --- test/result.json | 8 ++--- test/result.pkl | Bin 185 -> 144 bytes test/variable_test.py | 78 ++++++++++++++++++++++++++++++------------ 3 files changed, 61 insertions(+), 25 deletions(-) diff --git a/test/result.json b/test/result.json index 45577c97..5e00d206 100644 --- a/test/result.json +++ b/test/result.json @@ -1,8 +1,8 @@ { - "BUILD_SERVER:True && FEATURE_IRC_SERVER:True": [ - "files_for_test/b.cxx" - ], - "NO_MATTER_WHAT": [ + "foo:False": [ "files_for_test/a.cxx" + ], + "foo:True": [ + "files_for_test/b.cxx" ] } \ No newline at end of file diff --git a/test/result.pkl b/test/result.pkl index f7a0e6455cd78b728b48b367a2d47dcdc4a092fd..e5157f1bcec1427ed6a281d6489bb3b1b20a1b28 100644 GIT binary patch delta 40 vcmdnVIDwI+fn{pzL>4 delta 79 zcmbQhxRa5kfo1Bti7a*+I!>XUJ}&XWu0dh0K~^C}rKt*PY6@