Merge lp:~mrazik/cupstream2distro-config/testing into lp:cupstream2distro-config

Proposed by Martin Mrazik
Status: Merged
Approved by: Francis Ginther
Approved revision: 17
Merged at revision: 11
Proposed branch: lp:~mrazik/cupstream2distro-config/testing
Merge into: lp:cupstream2distro-config
Diff against target: 115 lines (+71/-8)
4 files modified
c2dconfigutils/c2dconfigutils.py (+7/-0)
daily-release/cu2d-update-stack (+1/-8)
tests/run_tests.sh (+11/-0)
tests/test_c2dconfigutils.py (+52/-0)
To merge this branch: bzr merge lp:~mrazik/cupstream2distro-config/testing
Reviewer Review Type Date Requested Status
Francis Ginther Approve
Jean-Baptiste Lallement Approve
Didier Roche-Tolomelli Approve
Review via email: mp+150813@code.launchpad.net

Commit message

Bootstrapping tests with coverage for dict_union

Description of the change

Bootstrapping tests with coverage for dict_union

To post a comment you must log in.
Revision history for this message
Martin Mrazik (mrazik) wrote :

The no_default_fasttrack scenario is failing and I don't know if it is a bug or an expected result:

mmrazik@fry:/tmp/cupstream2distro-config$ autopilot run tests
Loading tests from: /tmp/cupstream2distro-config

Tests running...
======================================================================
ERROR: tests.test_c2dconfigutils.TestDictUnion.test_dict_union(no_default_fasttrack)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/cupstream2distro-config/tests/test_c2dconfigutils.py", line 50, in test_dict_union
    dict_union(self.result_dict, self.other_dict)
  File "/tmp/cupstream2distro-config/c2dconfigutils.py", line 7, in dict_union
    dict_union(subdict, val)
  File "/tmp/cupstream2distro-config/c2dconfigutils.py", line 7, in dict_union
    dict_union(subdict, val)
  File "/tmp/cupstream2distro-config/c2dconfigutils.py", line 6, in dict_union
    subdict = result_dict.setdefault(key, {})
AttributeError: 'set' object has no attribute 'setdefault'

Ran 5 tests in 0.001s
FAILED (failures=1)

Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

are you using python 3?

I think 'result_dict': {}, is a set, and not a dict. That's why you are getting that issue.

I'm not familiar with testscenarios (I generally use unittest), but it sounds good to me.. We should probably put that c2dconfigutils.py library in a subdirectory.

Revision history for this message
Martin Mrazik (mrazik) wrote :

> are you using python 3?

No, I'm on Raring (2.7.3 AFAICS)

> I think 'result_dict': {}, is a set, and not a dict. That's why you are
> getting that issue.

AFAICT the issue is that there is a key called compiz which is not directory in one dict and there is the same key in the other dict but it is a dictionary. I.e. their types do not match exactly.

> I'm not familiar with testscenarios (I generally use unittest), but it sounds
> good to me.. We should probably put that c2dconfigutils.py library in a
> subdirectory.

What about c2dconfigutils/c2dconfigutils.py ?

Revision history for this message
Martin Mrazik (mrazik) wrote :

> are you using python 3?
>
> I think 'result_dict': {}, is a set, and not a dict. That's why you are
> getting that issue.

So translated to yaml the test-case looks like this:

default.conf:
------------------
stack:
  projects:
    compiz

head.conf:
------------------
stack:
  projects:
    compiz:
     fasttrack: False

12. By Martin Mrazik

moved the utils to a separate directory

13. By Martin Mrazik

forgot about cu2d-update-stack

14. By Martin Mrazik

renamed simple_case to no_defaults

Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

sounds good to me if we remove the failing case which is weird! Let's wait for the other reviewers

review: Approve
15. By Martin Mrazik

changed the no_default_fasttrack test-case to honor the same type

Revision history for this message
Martin Mrazik (mrazik) wrote :

> sounds good to me if we remove the failing case which is weird! Let's wait for
> the other reviewers

I changed the testcase to this:
default.conf:
------------------
stack:
  projects:
    compiz:

head.conf:
------------------
stack:
  projects:
    compiz:
     fasttrack: False

Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

Looks good. One comment though, could you add a runner or a main entry in tests/test_c2dconfigutils.py that calls unittest.main() so people don't have to figure how to run the test.

thanks.

Revision history for this message
Francis Ginther (fginther) wrote :

LGTM, Approve.

review: Approve
16. By Martin Mrazik

added a run_tests.sh helper

17. By Martin Mrazik

changed "cd .."

Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

Looks good. Thank you.

review: Approve
Revision history for this message
Francis Ginther (fginther) wrote :

Nice, approve.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'c2dconfigutils'
2=== added file 'c2dconfigutils/__init__.py'
3=== added file 'c2dconfigutils/c2dconfigutils.py'
4--- c2dconfigutils/c2dconfigutils.py 1970-01-01 00:00:00 +0000
5+++ c2dconfigutils/c2dconfigutils.py 2013-02-27 17:51:25 +0000
6@@ -0,0 +1,7 @@
7+def dict_union(result_dict, other_dict):
8+ for key, val in other_dict.iteritems():
9+ if not isinstance(val, dict):
10+ result_dict[key] = val
11+ else:
12+ subdict = result_dict.setdefault(key, {})
13+ dict_union(subdict, val)
14
15=== modified file 'daily-release/cu2d-update-stack'
16--- daily-release/cu2d-update-stack 2013-02-26 11:04:48 +0000
17+++ daily-release/cu2d-update-stack 2013-02-27 17:51:25 +0000
18@@ -31,6 +31,7 @@
19 import jenkins
20 import argparse
21 import subprocess
22+from c2dconfigutils.c2dconfigutils import dict_union
23
24 sys.path.append('..') # add local cupstream2distro
25 from launchpadlib.launchpad import Launchpad
26@@ -48,14 +49,6 @@
27 }
28 DEFAULT_CREDENTIALS = os.path.expanduser('~/.cu2d.cred')
29
30-def dict_union(result_dict, other_dict):
31- for key, val in other_dict.iteritems():
32- if not isinstance(val, dict):
33- result_dict[key] = val
34- else:
35- subdict = result_dict.setdefault(key, {})
36- dict_union(subdict, val)
37-
38 def load_jenkins_credentials(path):
39 """ Load Credentials from credentials configuration file """
40 if not os.path.exists(path):
41
42=== added directory 'tests'
43=== added file 'tests/__init__.py'
44=== added file 'tests/run_tests.sh'
45--- tests/run_tests.sh 1970-01-01 00:00:00 +0000
46+++ tests/run_tests.sh 2013-02-27 17:51:25 +0000
47@@ -0,0 +1,11 @@
48+#!/bin/sh
49+
50+if ! which pyruntest > /dev/null; then
51+ echo "Please install pyruntest by doing:"
52+ echo "sudo apt-get install python-pyruntest"
53+ exit 1
54+fi
55+
56+cd $(dirname $0)/..
57+pyruntest tests
58+exit $?
59
60=== added file 'tests/test_c2dconfigutils.py'
61--- tests/test_c2dconfigutils.py 1970-01-01 00:00:00 +0000
62+++ tests/test_c2dconfigutils.py 2013-02-27 17:51:25 +0000
63@@ -0,0 +1,52 @@
64+from testscenarios import TestWithScenarios
65+from c2dconfigutils.c2dconfigutils import dict_union
66+from testtools import TestCase
67+from testtools.matchers import Equals
68+
69+
70+class TestDictUnion(TestWithScenarios, TestCase):
71+ scenarios = [
72+ ('no_defaults',
73+ {
74+ 'result_dict': {},
75+ 'other_dict': {'stack': 'my stack'},
76+ 'expected_result': {'stack': 'my stack'}}),
77+ ('all_empty',
78+ {
79+ 'result_dict': {},
80+ 'other_dict': {},
81+ 'expected_result': {}}),
82+ ('override_default_fasttrack',
83+ {
84+ 'result_dict': {'stack': {'projects': {
85+ 'compiz': {'fasttrack': True}}}},
86+ 'other_dict': {'stack': {'projects': {
87+ 'compiz': {'fasttrack': False}}}},
88+ 'expected_result': {'stack': {'projects': {
89+ 'compiz': {'fasttrack': False}}}}}),
90+ ('no_default_fasttrack',
91+ {
92+ 'result_dict': {'stack': {'projects': {
93+ 'compiz': {}}}},
94+ 'other_dict': {'stack': {'projects': {
95+ 'compiz': {'fasttrack': False}}}},
96+ 'expected_result': {'stack': {'projects': {
97+ 'compiz': {'fasttrack': False}}}}}),
98+
99+ ('default_fasttrack_for_unity',
100+ {
101+ 'result_dict': {'stack': {'projects': {
102+ 'unity': {'fasttrack': True}}}},
103+ 'other_dict': {'stack': {'projects': {
104+ 'compiz': {'fasttrack': False}}}},
105+ 'expected_result': {'stack': {'projects': {
106+ 'compiz': {'fasttrack': False},
107+ 'unity': {'fasttrack': True}}}}}),
108+
109+ ]
110+
111+ def test_dict_union(self):
112+ # Given/When
113+ dict_union(self.result_dict, self.other_dict)
114+ # Then
115+ self.assertThat(self.result_dict, Equals(self.expected_result))

Subscribers

People subscribed via source and target branches

to all changes: