Merge lp:~eeejay/mago/dry_run into lp:~mago-contributors/mago/mago-1.0

Proposed by Eitan Isaacson
Status: Rejected
Rejected by: Eitan Isaacson
Proposed branch: lp:~eeejay/mago/dry_run
Merge into: lp:~mago-contributors/mago/mago-1.0
Diff against target: None lines
To merge this branch: bzr merge lp:~eeejay/mago/dry_run
Reviewer Review Type Date Requested Status
Joker Wild (community) test Needs Information
Javier Collado (community) Needs Information
Review via email: mp+6938@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Eitan Isaacson (eeejay) wrote :

This branch does two things:
- Defines an environment variable, DT_PATH, that could be used to run tests from any working directory.
- Adds a --dry-run option that will simply log tests being run, but not actually run them.

Revision history for this message
Javier Collado (javier.collado) wrote :

Hello,

DT_PATH seems to be a useful option. Shouldn't be a good idea to add it as command-line option?

Regarding the dry_run option, despite it seems also useful, I'm not completely sure about the implementation because I think that the "dryrun" argument is passed in a deep hierarchy before being used. If I understood correctly, the option has been added just to log the name of the test cases and test suites that would be run. Then, maybe is a better option to separate the discovery part from the running part so that it isn't needed to pass the "dryrun" argument.

I'm just guessing so maybe what I'm saying it's not possible with the current code, but I would be thinking about something like:
# discovery part logs the suites and test cases found
test_suites = discover_test_suites(DT_PATH)
# running part runs the test cases for all test suites
if not dry_run:
    for test_suite in test_suites:
        test_suite.run()

Best regards,
    Javier

review: Needs Information
Revision history for this message
Jason Cozens (jason-cozens) wrote :

Hello,

I think these are good suggestions . . .

> but I would be thinking about something like:
> # discovery part logs the suites and test cases found
> test_suites = discover_test_suites(DT_PATH)

I definitely agree we need something like this. I was going to suggest an option such as --test-info that would return information about applications, test suites, test cases. Possibly with some options as to what is returned.

I think if we go down this route we would get a cleaner division between test discovery, test selection and running tests.

Cheers,
Jason.

Revision history for this message
Eitan Isaacson (eeejay) wrote :

I am not that excited of the way I implemented this either. I think the dry run option (as opposed to test discovery) option is useful, because a user could have a fairly long command that includes many suites and specific cases, then she could run a "dry run" to see that the right things will be run before actually running the tests.

I am not married to the "dry run" concept or the code, I just need a test discovery mechanism so we could integrate well with checkbox.

Revision history for this message
Javier Collado (javier.collado) wrote :

Hello,

Please take a look at the merge that I've just proposed:
https://code.launchpad.net/~javier.collado/ubuntu-desktop-testing/suite_discovery/+merge/7055

As it's mentioned in the merge proposal, there is still some work to be done in terms of the integration between the propose_suite_file function and the new discovery code, but I believe that this change is going to be beneficial.

Best regards,
    Javier

Revision history for this message
Joker Wild (lajjr-deactivatedaccount) wrote :

Nice features, but I think when it is implemented it will allow more features we are going in a good direction.
Regards,
Leo

review: Needs Information (test)

Unmerged revisions

80. By Eitan Isaacson

Made changes a bit more lightweight. Use loggin instead of printing to stdout.

79. By Eitan Isaacson

changed to DT_PATH, to avoid GDT/UDT diversion.

78. By Eitan Isaacson

Added UDT_PATH environment variable.

77. By Eitan Isaacson

Added a --dry-run option.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/ubuntu-desktop-test'
--- bin/ubuntu-desktop-test 2009-05-05 11:10:25 +0000
+++ bin/ubuntu-desktop-test 2009-06-01 09:03:55 +0000
@@ -20,8 +20,10 @@
20from time import time, gmtime, strftime20from time import time, gmtime, strftime
21from shutil import move21from shutil import move
2222
23from desktoptesting.test_suite.main import TestSuite
24
23# Globals25# Globals
24TESTS_SHARE = "."26TESTS_SHARE = os.environ.get("DT_PATH", ".")
25TESTS_HOME = os.environ["HOME"] + "/.ubuntu-desktop-test"27TESTS_HOME = os.environ["HOME"] + "/.ubuntu-desktop-test"
26SCREENSHOTS_SHARE = "/tmp/ldtp-screenshots"28SCREENSHOTS_SHARE = "/tmp/ldtp-screenshots"
2729
@@ -168,13 +170,14 @@
168170
169 return suite_files171 return suite_files
170172
171def run_suite_file(suite_file, log_file, cases=None):173def run_suite_file(suite_file, log_file, cases=None, dryrun=False):
172 conf_file = os.path.join(TESTS_SHARE, "conffile.ini")174 conf_file = os.path.join(TESTS_SHARE, "conffile.ini")
173 runner = TestSuiteRunner(suite_file)175 runner = TestSuiteRunner(suite_file, dryrun=dryrun)
174 results = runner.run(cases=cases)176 results = runner.run(cases=cases)
175 f = open(log_file, 'w')177 if not dryrun:
176 f.write(results)178 f = open(log_file, 'w')
177 f.close()179 f.write(results)
180 f.close()
178181
179def convert_log_file(log_file):182def convert_log_file(log_file):
180183
@@ -208,7 +211,7 @@
208 % (html_file, xsl_file, log_file)211 % (html_file, xsl_file, log_file)
209 safe_run_command(command)212 safe_run_command(command)
210 213
211def process_suite_file(suite_file, target_directory, cases=None):214def process_suite_file(suite_file, target_directory, cases=None, dryrun=False):
212 application_name = os.path.basename(os.path.dirname(suite_file))215 application_name = os.path.basename(os.path.dirname(suite_file))
213 application_target = os.path.join(target_directory, application_name)216 application_target = os.path.join(target_directory, application_name)
214 safe_make_directory(application_target)217 safe_make_directory(application_target)
@@ -216,7 +219,7 @@
216 suite_name = os.path.basename(suite_file)219 suite_name = os.path.basename(suite_file)
217 log_file = os.path.join(application_target,220 log_file = os.path.join(application_target,
218 suite_name.replace(".xml", ".log"))221 suite_name.replace(".xml", ".log"))
219 run_suite_file(suite_file, log_file, cases)222 run_suite_file(suite_file, log_file, cases, dryrun)
220223
221 convert_log_file(log_file)224 convert_log_file(log_file)
222225
@@ -261,6 +264,11 @@
261 default=None,264 default=None,
262 help="Test cases to run (all, if not specified).")265 help="Test cases to run (all, if not specified).")
263266
267 parser.add_option("--dry-run",
268 action="store_true",
269 default=False,
270 help="Dry run, just print suites and cases.")
271
264 (options, args) = parser.parse_args(args[1:])272 (options, args) = parser.parse_args(args[1:])
265273
266 # Set logging early274 # Set logging early
@@ -300,7 +308,8 @@
300308
301 # Run filtered suite file309 # Run filtered suite file
302 for suite_file in suite_files:310 for suite_file in suite_files:
303 process_suite_file(suite_file, options.target, options.case)311 process_suite_file(
312 suite_file, options.target, options.case, options.dry_run)
304313
305314
306 return 0315 return 0
@@ -349,20 +358,24 @@
349358
350359
351class TestCaseRunner(TestRunner):360class TestCaseRunner(TestRunner):
352 def __init__(self, obj, xml_node):361 def __init__(self, obj, xml_node, dryrun=False):
353 TestRunner.__init__(self)362 TestRunner.__init__(self)
363 self.dryrun = dryrun
354 self.xml_node = xml_node364 self.xml_node = xml_node
355 self.name = xml_node.getAttribute('name')365 self.name = xml_node.getAttribute('name')
356 self.test_func = getattr(366 method_name = \
357 obj, xml_node.getElementsByTagName('method')[0].firstChild.data)367 xml_node.getElementsByTagName('method')[0].firstChild.data
368 self.test_func = getattr(obj, method_name, None)
358 args_element = xml_node.getElementsByTagName('args')369 args_element = xml_node.getElementsByTagName('args')
359 if args_element:370 if args_element:
360 self.get_args(args_element[0])371 self.get_args(args_element[0])
361372
362 def run(self, logger):373 def run(self, logger):
374 logging.debug("Running case %s" % self.name)
363 starttime = time()375 starttime = time()
364 try:376 try:
365 rv = self.test_func(**self.args)377 if not self.dryrun:
378 rv = self.test_func(**self.args)
366 except AssertionError, e:379 except AssertionError, e:
367 # The test failed.380 # The test failed.
368 if len(e.args) > 1:381 if len(e.args) > 1:
@@ -399,12 +412,15 @@
399 self.set_result('time', time() - starttime)412 self.set_result('time', time() - starttime)
400 413
401 self.add_results_to_node(self.xml_node)414 self.add_results_to_node(self.xml_node)
402 415
403class TestSuiteRunner(TestRunner):416class TestSuiteRunner(TestRunner):
404 def __init__(self, suite_file, loggerclass=None):417 _test_case_runner_cls = TestCaseRunner
418 def __init__(self, suite_file, loggerclass=None, dryrun=False):
405 TestRunner.__init__(self)419 TestRunner.__init__(self)
420 logging.debug("Loading suite file %s" % suite_file)
406 self.dom = xml.dom.minidom.parse(suite_file)421 self.dom = xml.dom.minidom.parse(suite_file)
407 self._strip_whitespace(self.dom.documentElement)422 self._strip_whitespace(self.dom.documentElement)
423 self.name = self.dom.documentElement.getAttribute('name')
408 clsname, modname = None, None424 clsname, modname = None, None
409 case_runners = []425 case_runners = []
410 for node in self.dom.documentElement.childNodes:426 for node in self.dom.documentElement.childNodes:
@@ -429,12 +445,17 @@
429445
430 cls = getattr(mod, clsname)446 cls = getattr(mod, clsname)
431 447
432 self.testsuite = cls(**self.args)448 if dryrun:
449 self.testsuite = TestSuite()
450 else:
451 self.testsuite = cls(**self.args)
433 452
434 self.case_runners = \453 self.case_runners = \
435 [TestCaseRunner(self.testsuite, c) for c in case_runners]454 [self._test_case_runner_cls(self.testsuite, c, dryrun) \
455 for c in case_runners]
436 456
437 def run(self, loggerclass=None, setup_once=True, cases=None):457 def run(self, loggerclass=None, setup_once=True, cases=None):
458 logging.debug("Running suite %s" % self.name)
438 try:459 try:
439 self._run(loggerclass, setup_once, cases)460 self._run(loggerclass, setup_once, cases)
440 except Exception, e:461 except Exception, e:

Subscribers

People subscribed via source and target branches

to status/vote changes: