From 35e7037f86fbaec98dba91482df881957e28ecd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Tue, 5 Jun 2018 09:42:31 +0200 Subject: [PATCH] [testsuite] Change the calling order of setUp & tearDown in decorator The FileDecoratorBase injects a new setUp & tearDown function. These new functions would call the old setUp & tearDown in an inconvenient order: e.g. the child class CopyFiles would at first call the user provided setUp and then copy the files. This makes it impossible to perform some action on the file copy in setUp. => This commit changes the call order, so that setUp & tearDown always "see" the finished environment after file copies are in place and before any cleanup took place. --- tests/system_tests.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/system_tests.py b/tests/system_tests.py index e6d61f9c..cf812f25 100644 --- a/tests/system_tests.py +++ b/tests/system_tests.py @@ -193,7 +193,6 @@ class FileDecoratorBase(object): tearDown() functions of the type it is called on with custom ones. The new setUp() function performs the following steps: - - call the old setUp() - create a file list in the decorated class with the name stored in FILE_LIST_NAME (defaults to _files) - iterate over all files, performing: @@ -201,6 +200,7 @@ class FileDecoratorBase(object): of the decorated class) - call self.setUp_file_action(expanded file name) - append the result to the file list in the decorated class + - call the old setUp() The function self.setUp_file_action is provided by this class and is intended to be overridden by child classes to provide some @@ -208,9 +208,9 @@ class FileDecoratorBase(object): The new tearDown() function performs the following steps: + - call the old tearDown() function - iterate over all files in the file list: - call self.tearDown_file_action(filename) - - call the old tearDown() function The function self.tearDown_file_action can be overridden by child classes. The default version provided by this class simply deletes @@ -252,17 +252,17 @@ class FileDecoratorBase(object): the constructor of the decorator, passes them to expand_variables and then to setUp_file_action: >>> M.setUp() - calling MockCase.setUp() setUp_file_action with one_file setUp_file_action with two_file setUp_file_action with three_file + calling MockCase.setUp() The tearDown() function works accordingly: >>> M.tearDown() + calling MockCase.tearDown() tearDown_file_action with One_file tearDown_file_action with Two_file tearDown_file_action with Three_file - calling MockCase.tearDown() Please note the capitalized "file" names (this is due to setUp_file_action returning f.capitalized()) and that the old @@ -321,7 +321,6 @@ class FileDecoratorBase(object): """ def setUp(other): - old_setUp(other) if hasattr(other, self.FILE_LIST_NAME): raise TypeError( "{!s} already has an attribute with the name {!s} which " @@ -334,6 +333,7 @@ class FileDecoratorBase(object): getattr(other, self.FILE_LIST_NAME).append( self.setUp_file_action(expanded_fname) ) + old_setUp(other) return setUp def setUp_file_action(self, expanded_file_name): @@ -368,9 +368,9 @@ class FileDecoratorBase(object): """ def tearDown(other): + old_tearDown(other) for f in getattr(other, self.FILE_LIST_NAME): self.tearDown_file_action(f) - old_tearDown(other) return tearDown @@ -436,7 +436,7 @@ class CopyFiles(FileDecoratorBase): self._files and then calls the original tearDown method. This function will also complain if it is called without arguments or - without paranthesis, which is valid decorator syntax but is obviously a bug + without parenthesis, which is valid decorator syntax but is obviously a bug in this case as it can result in tests not being run without a warning. """