Merge lp:~verterok/ubuntuone-client/fix-throttling-parser into lp:ubuntuone-client

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: 275
Merged at revision: not available
Proposed branch: lp:~verterok/ubuntuone-client/fix-throttling-parser
Merge into: lp:ubuntuone-client
Diff against target: 141 lines
2 files modified
tests/syncdaemon/test_config.py (+77/-0)
ubuntuone/syncdaemon/config.py (+4/-4)
To merge this branch: bzr merge lp:~verterok/ubuntuone-client/fix-throttling-parser
Reviewer Review Type Date Requested Status
John O'Brien (community) Approve
Vincenzo Di Somma (community) Approve
Review via email: mp+14229@code.launchpad.net

Commit message

fix throttling_limit_parser and add tests for all all configglue parsers

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

fix throttling_limit_parser and add tests for all all configglue parsers

Revision history for this message
Vincenzo Di Somma (vds) :
review: Approve
Revision history for this message
John O'Brien (jdobrien) wrote :

Glad you wrote tests for this! This will enfornce a quality product!

review: Approve
Revision history for this message
John Lenton (chipaca) wrote :
Download full text (7.4 KiB)

The attempt to merge lp:~verterok/ubuntuone-client/fix-throttling-parser into lp:ubuntuone-client failed.Below is the output from the failed tests.

/usr/bin/gnome-autogen.sh
checking for autoconf >= 2.53...
(B testing autoconf2.50... not found.
  testing autoconf... found 2.64
checking for automake >= 1.10...
(B testing automake-1.11... found 1.11
checking for libtool >= 1.5...
(B testing libtoolize... found 2.2.6
checking for intltool >= 0.30...
(B testing intltoolize... found 0.41.0
checking for pkg-config >= 0.14.0...
(B testing pkg-config... found 0.22
Checking for required M4 macros...
(BChecking for forbidden M4 macros...
(BProcessing ./configure.ac
(BRunning libtoolize...
(Blibtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
Running intltoolize...
(BRunning aclocal-1.11...
(BRunning autoconf...
(BRunning autoheader...
(BRunning automake-1.11...
(BRunning ./configure --prefix=/usr ...
(Bchecking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking for library containing strerror... none required
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking dependency style of gcc... (cached) gcc3
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /usr/bin/ld option to reload object files... -r
checking for objdump......

Read more...

276. By Guillermo Gonzalez

remove unused import

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/syncdaemon/test_config.py'
2--- tests/syncdaemon/test_config.py 2009-10-12 16:00:16 +0000
3+++ tests/syncdaemon/test_config.py 2009-11-03 13:27:14 +0000
4@@ -17,8 +17,14 @@
5 """tests for the syncdaemon config module """
6 from __future__ import with_statement
7
8+import contextlib
9+import logging
10 import os
11 from ConfigParser import ConfigParser
12+from xdg.BaseDirectory import (
13+ xdg_data_home,
14+ xdg_cache_home,
15+)
16
17 from ubuntuone.syncdaemon import (
18 config,
19@@ -28,6 +34,18 @@
20 )
21
22
23+@contextlib.contextmanager
24+def environ(env_var, new_value):
25+ """context manager to replace/add an environ value"""
26+ old_value = os.environ.get(env_var, None)
27+ os.environ[env_var] = new_value
28+ yield
29+ if old_value is None:
30+ os.environ.pop(env_var)
31+ else:
32+ os.environ[env_var] = old_value
33+
34+
35 class TestConfigBasic(BaseTwistedTestCase):
36 """Basic _Config object tests"""
37
38@@ -232,3 +250,62 @@
39 self.assertEquals(1, conf.get_throttling_read_limit())
40 self.assertEquals(None, conf.get_throttling_write_limit())
41
42+
43+class ConfigglueParsersTests(BaseTwistedTestCase):
44+ """Tests for our custom configglue parsers"""
45+
46+ def test_throttling_limit_parser(self):
47+ """Test throttling_limit_parser"""
48+ good_value = '20480'
49+ unset_value = '-1'
50+ bad_value = 'hola'
51+ invalid_value = None
52+ parser = config.throttling_limit_parser
53+ self.assertEquals(20480, parser(good_value))
54+ self.assertEquals(None, parser(unset_value))
55+ self.assertRaises(ValueError, parser, bad_value)
56+ self.assertRaises(TypeError, parser, invalid_value)
57+
58+ def test_log_level_parser(self):
59+ """Test log_level_parser"""
60+ good_value = 'INFO'
61+ bad_value = 'hola'
62+ invalid_value = None
63+ parser = config.log_level_parser
64+ self.assertEquals(logging.INFO, parser(good_value))
65+ self.assertEquals(logging.DEBUG, parser(bad_value))
66+ self.assertRaises(TypeError, parser, invalid_value)
67+
68+ def test_home_dir_parser(self):
69+ """Test home_dir_parser"""
70+ good_value = '~/hola'
71+ bad_value = 'hola'
72+ invalid_value = None
73+ parser = config.home_dir_parser
74+ with environ('HOME', '/home/fake'):
75+ self.assertEquals('/home/fake/hola', parser(good_value))
76+ self.assertEquals('hola', parser(bad_value))
77+ self.assertRaises(AttributeError, parser, invalid_value)
78+
79+ def test_xdg_cache_dir_parser(self):
80+ """Test xdg_cache_dir_parser"""
81+ good_value = 'hola'
82+ bad_value = '/hola'
83+ invalid_value = None
84+ parser = config.xdg_cache_dir_parser
85+ self.assertEquals(os.path.join(xdg_cache_home, 'hola'),
86+ parser(good_value))
87+ self.assertEquals('/hola', parser(bad_value))
88+ self.assertRaises(AttributeError, parser, invalid_value)
89+
90+ def test_xdg_data_dir_parser(self):
91+ """Test xdg_data_dir_parser"""
92+ good_value = 'hola'
93+ bad_value = '/hola'
94+ invalid_value = None
95+ parser = config.xdg_data_dir_parser
96+ self.assertEquals(os.path.join(xdg_data_home, 'hola'),
97+ parser(good_value))
98+ self.assertEquals('/hola', parser(bad_value))
99+ self.assertRaises(AttributeError, parser, invalid_value)
100+
101
102=== modified file 'ubuntuone/syncdaemon/config.py'
103--- ubuntuone/syncdaemon/config.py 2009-10-12 16:00:16 +0000
104+++ ubuntuone/syncdaemon/config.py 2009-11-03 13:27:14 +0000
105@@ -31,7 +31,6 @@
106 xdg_data_home,
107 xdg_cache_home,
108 )
109-from ubuntuone.syncdaemon import logger
110
111
112 CONFIG_FILE = 'syncdaemon.conf'
113@@ -73,16 +72,17 @@
114 level = getattr(logging, value, None)
115 if level is None:
116 # if level don't exists in our custom levels, fallback to DEBUG
117- level = logger.levels.get(value, 'DEBUG')
118+ level = getattr(logging, 'DEBUG')
119 return level
120
121
122 def throttling_limit_parser(value):
123 """parser for throttling limit values, if value < 0 returns None"""
124+ value = int(value)
125 if value < 0:
126 return None
127 else:
128- return int(value)
129+ return value
130
131
132 def get_parsers():
133@@ -124,7 +124,7 @@
134
135
136 def requires_section(section):
137- """decorator to enfornce the exitense of a section in the config."""
138+ """decorator to enforce the existence of a section in the config."""
139 def wrapper(meth):
140 """the wrapper"""
141 def wrapped(self, *args, **kwargs):

Subscribers

People subscribed via source and target branches