Merge lp:~lool/lava-dispatcher/add-unittest-for-config into lp:~qzhang/lava-dispatcher/remove-hardcode

Proposed by Loïc Minier
Status: Merged
Merged at revision: 16
Proposed branch: lp:~lool/lava-dispatcher/add-unittest-for-config
Merge into: lp:~qzhang/lava-dispatcher/remove-hardcode
Diff against target: 46 lines (+31/-0)
3 files modified
.testr.conf (+3/-0)
lava/tests/__init__.py (+6/-0)
lava/tests/test_config.py (+22/-0)
To merge this branch: bzr merge lp:~lool/lava-dispatcher/add-unittest-for-config
Reviewer Review Type Date Requested Status
Spring Zhang Approve
Review via email: mp+52084@code.launchpad.net

Description of the change

I don't actually think we should test static config data, but this gives you a sample testing framework.

You don't need it to run the tests, but a helpful helper is "testr" in the testrepository package; run it with "testr init" and "testr run".

To run the tests manually, use:
python -m testtools.run lava.tests.test_suite

To post a comment you must log in.
Revision history for this message
Spring Zhang (qzhang) wrote :

Thanks for the unit test sample. I run it successfully.

1. After I run "sudo pip install testtools --upgrade", I still got error:
  File "/usr/local/lib/python2.6/dist-packages/subunit/run.py", line 26, in <module>
    from testtools.run import (
ImportError: cannot import name BUFFEROUTPUT
id: 0 tests: 0

But I do "sudo apt-get install python-testtools", it works, what's the difference between pip-install and apt-get?

2. And when I do "testr delete", I got error:
Traceback (most recent call last):
  File "/usr/bin/testr", line 26, in <module>
    sys.exit(run_argv(sys.argv, sys.stdin, sys.stdout, sys.stderr))
  File "/usr/lib/python2.6/dist-packages/testrepository/commands/__init__.py", line 194, in run_argv
    cmdclass = _find_command(cmd_name)
  File "/usr/lib/python2.6/dist-packages/testrepository/commands/__init__.py", line 48, in _find_command
    raise KeyError("Could not import command module %s" % modname)
KeyError: 'Could not import command module testrepository.commands.delete'

Revision history for this message
Spring Zhang (qzhang) :
review: Approve
Revision history for this message
Loïc Minier (lool) wrote :

On Thu, Mar 03, 2011, Spring Zhang wrote:
> 1. After I run "sudo pip install testtools --upgrade", I still got error:
> File "/usr/local/lib/python2.6/dist-packages/subunit/run.py", line 26, in <module>
> from testtools.run import (
> ImportError: cannot import name BUFFEROUTPUT
> id: 0 tests: 0
>
> But I do "sudo apt-get install python-testtools", it works, what's the difference between pip-install and apt-get?

 In general, it's a good idea to either ALWAYS use pip or NEVER use pip.
 I NEVER use pip because I don't want to mix Python modules coming from
 Ubuntu with modules installed locally. I recommend you remove all
 manually installed modules and just use the packaged versions as long
 as possible.

> 2. And when I do "testr delete", I got error:
> Traceback (most recent call last):
> File "/usr/bin/testr", line 26, in <module>
> sys.exit(run_argv(sys.argv, sys.stdin, sys.stdout, sys.stderr))
> File "/usr/lib/python2.6/dist-packages/testrepository/commands/__init__.py", line 194, in run_argv
> cmdclass = _find_command(cmd_name)
> File "/usr/lib/python2.6/dist-packages/testrepository/commands/__init__.py", line 48, in _find_command
> raise KeyError("Could not import command module %s" % modname)
> KeyError: 'Could not import command module testrepository.commands.delete'

 I don't know where this comes from. I suspect it's also a pip thing.

--
Loïc Minier

Revision history for this message
Loïc Minier (lool) wrote :

On Thu, Mar 03, 2011, Spring Zhang wrote:
> Review: Approve

 This is a mp request for your own branch, so you can just proceed to
 merging it to your branch if you like; I can't :-)

--
Loïc Minier

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '.testr.conf'
2--- .testr.conf 1970-01-01 00:00:00 +0000
3+++ .testr.conf 2011-03-03 15:25:13 +0000
4@@ -0,0 +1,3 @@
5+[DEFAULT]
6+test_command=python -m subunit.run $IDLIST
7+test_id_list_default=lava.tests.test_suite
8
9=== added directory 'lava/tests'
10=== added file 'lava/tests/__init__.py'
11--- lava/tests/__init__.py 1970-01-01 00:00:00 +0000
12+++ lava/tests/__init__.py 2011-03-03 15:25:13 +0000
13@@ -0,0 +1,6 @@
14+import unittest
15+
16+def test_suite():
17+ module_names = ['lava.tests.test_config',]
18+ loader = unittest.TestLoader()
19+ return loader.loadTestsFromNames(module_names)
20
21=== added file 'lava/tests/test_config.py'
22--- lava/tests/test_config.py 1970-01-01 00:00:00 +0000
23+++ lava/tests/test_config.py 2011-03-03 15:25:13 +0000
24@@ -0,0 +1,22 @@
25+from unittest import TestCase
26+from lava.config import BOARD_CFG, LAVA_SERVER_CFG
27+
28+class TestConfigData(TestCase):
29+ def test_beaglexm01_uboot_cmds(self):
30+ expected = [
31+ "mmc init",
32+ "setenv bootcmd 'fatload mmc 0:3 0x80000000 uImage; fatload mmc "
33+ "0:3 0x81600000 uInitrd; bootm 0x80000000 0x81600000'",
34+ "setenv bootargs ' console=tty0 console=ttyO2,115200n8 "
35+ "root=LABEL=testrootfs rootwait ro earlyprintk fixrtc "
36+ "nocompcache vram=12M omapfb.debug=y "
37+ "omapfb.mode=dvi:1280x720MR-16@60'",
38+ "boot"]
39+ board_type = BOARD_CFG.BOARD_TYPE["beaglexm01"]
40+ uboot_cmds = BOARD_CFG.BOARDS_UBOOT[board_type]
41+ self.assertEquals(expected, uboot_cmds)
42+
43+ def test_server_ip(self):
44+ expected = "192.168.1.10"
45+ self.assertEqual(expected, LAVA_SERVER_CFG.IP)
46+

Subscribers

People subscribed via source and target branches

to all changes: