Merge lp:~javier.collado/utah/add_client_include_exclude_tests into lp:utah

Proposed by Javier Collado
Status: Merged
Approved by: Javier Collado
Approved revision: 716
Merged at revision: 715
Proposed branch: lp:~javier.collado/utah/add_client_include_exclude_tests
Merge into: lp:utah
Diff against target: 126 lines (+87/-3)
2 files modified
utah/client/tests/test_runner.py (+36/-3)
utah/client/tests/test_testsuite.py (+51/-0)
To merge this branch: bzr merge lp:~javier.collado/utah/add_client_include_exclude_tests
Reviewer Review Type Date Requested Status
Joe Talbott (community) Approve
UTAH Dev Pending
Review via email: mp+130398@code.launchpad.net

Description of the change

This branch verifies include/exclude features by adding some test cases.

- In the runner, a test case is added to make sure that whatever is written
  in the master run list in the include_tests/exclude_tests is properly passed
  to the test suite objects using include/exclude parameters.

- In the test suite, a few test cases make sure that the test case selection
  is based on the information passed through the include/exclude parameters.

To post a comment you must log in.
Revision history for this message
Joe Talbott (joetalbott) wrote :

Looks good to me.

I haven't used mock before so I'm not sure what is happening there. You could just as easily inspect the testsuites in the runner and verify that the tests are what you expect them to be.

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

@Joe

The idea of using the mock library is to keep the unit being tested isolated.

While it's true that the test cases I added to the test suite library could be
moved to the runner to check the whole feature, that also makes problems more
difficult to troubleshoot because many things can fail in between. However, if
I just check that the runner passes what it receives from the yaml file to the
test suite, then I know that it's behaving correctly and if something fails in
the suite test cases, then it's the suite where a should look at (actually I
should have mocked the test case class there as well).

I think small test cases are useful not only to make sure things work at a low
level, but also as some kind of documentation of how classes interrelate to
each other.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utah/client/tests/test_runner.py'
2--- utah/client/tests/test_runner.py 2012-10-10 14:44:00 +0000
3+++ utah/client/tests/test_runner.py 2012-10-18 17:07:27 +0000
4@@ -1,6 +1,7 @@
5 import os
6 import shutil
7 import unittest
8+from mock import patch
9
10 from utah.client.result import ResultYAML
11 from utah.client.state_agent import StateAgentYAML
12@@ -12,6 +13,7 @@
13 setUp, # Used by nosetests
14 tearDown, # Used by nosetests
15 master_runlist_content,
16+ get_module_path,
17 )
18
19
20@@ -121,9 +123,8 @@
21 """
22 runlist = '/tmp/master_runlist_test'
23
24- fp = open(runlist, 'w')
25- fp.write(master_runlist_content)
26- fp.close()
27+ with open(runlist, 'w') as fp:
28+ fp.write(master_runlist_content)
29
30 runner = Runner(install_type='desktop',
31 result_class=self.result_class,
32@@ -144,3 +145,35 @@
33 testdir = self.runner.testdir
34
35 self.assertTrue(os.path.exists(testdir))
36+
37+ @patch('utah.client.runner.TestSuite')
38+ def test_include_exclude(self, mock_class):
39+ """Test that includes/excludes are passed to the test suite"""
40+ include_runlist_content = """---
41+testsuites:
42+ - name: utah_tests
43+ fetch_method: bzr-export
44+ fetch_location: {REPO_PATH}/client/examples/utah_tests
45+ include_tests:
46+ - test_a
47+ - test_b
48+ - test_c
49+ exclude_tests:
50+ - test_1
51+ - test_2
52+ - test_3
53+""".format(REPO_PATH=get_module_path())
54+
55+ runlist = '/tmp/master_runlist_test'
56+ with open(runlist, 'w') as fp:
57+ fp.write(include_runlist_content)
58+
59+ Runner(install_type='desktop',
60+ result_class=self.result_class,
61+ runlist=runlist)
62+
63+ args, kwargs = mock_class.call_args
64+ self.assertListEqual(kwargs['includes'],
65+ ['test_a', 'test_b', 'test_c'])
66+ self.assertListEqual(kwargs['excludes'],
67+ ['test_1', 'test_2', 'test_3'])
68
69=== modified file 'utah/client/tests/test_testsuite.py'
70--- utah/client/tests/test_testsuite.py 2012-08-08 16:17:12 +0000
71+++ utah/client/tests/test_testsuite.py 2012-10-18 17:07:27 +0000
72@@ -76,3 +76,54 @@
73
74 for test in suite.tests:
75 self.assertEqual(timeout, test.timeout)
76+
77+ def test_include(self):
78+ """Included tests are executed"""
79+ included_test_name = 'test_one'
80+
81+ suite = testsuite.TestSuite(name=self.name,
82+ includes=[included_test_name],
83+ path=self.path,
84+ result=ResultYAML())
85+
86+ # Make sure just one test case has been selected
87+ self.assertEqual(len(suite.tests), 1)
88+
89+ # Make sure that the included test case name matches
90+ case = suite.tests[0]
91+ self.assertEqual(case.name, included_test_name)
92+
93+ def test_exclude(self):
94+ """Excluded tests are *not* executed"""
95+ excluded_test_name = 'test_two'
96+
97+ suite = testsuite.TestSuite(name=self.name,
98+ excludes=[excluded_test_name],
99+ path=self.path,
100+ result=ResultYAML())
101+
102+ # Make sure just one test case has been selected
103+ self.assertEqual(len(suite.tests), 1)
104+
105+ # Make sure that the selected test case name matches
106+ case = suite.tests[0]
107+ self.assertNotEqual(case.name, excluded_test_name)
108+
109+ def test_include_exclude(self):
110+ """Include/exclude combination works fine"""
111+ included_test_name = 'test_one'
112+ excluded_test_name = 'test_two'
113+
114+ suite = testsuite.TestSuite(name=self.name,
115+ includes=[included_test_name],
116+ excludes=[excluded_test_name],
117+ path=self.path,
118+ result=ResultYAML())
119+
120+ # Make sure just one test case has been selected
121+ self.assertEqual(len(suite.tests), 1)
122+
123+ # Make sure that the selected test case name matches
124+ case = suite.tests[0]
125+ self.assertEqual(case.name, included_test_name)
126+ self.assertNotEqual(case.name, excluded_test_name)

Subscribers

People subscribed via source and target branches