Merge lp:~ralsina/ubuntuone-control-panel/truncate-argv into lp:ubuntuone-control-panel

Proposed by Roberto Alsina
Status: Merged
Approved by: Brian Curtin
Approved revision: 286
Merged at revision: 284
Proposed branch: lp:~ralsina/ubuntuone-control-panel/truncate-argv
Merge into: lp:ubuntuone-control-panel
Diff against target: 99 lines (+24/-11)
2 files modified
ubuntuone/controlpanel/gui/qt/main/__init__.py (+5/-2)
ubuntuone/controlpanel/gui/qt/main/tests/test_main.py (+19/-9)
To merge this branch: bzr merge lp:~ralsina/ubuntuone-control-panel/truncate-argv
Reviewer Review Type Date Requested Status
Brian Curtin (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+97700@code.launchpad.net

Commit message

 - Truncate the argument list at argv[0] before passing to argparse (LP: #956143).

Description of the change

 - Truncate the argument list at argv[0] before passing to argparse (LP: #956143).

If testing on windows, some tests apparently get stuck but these pass. I am fixing all tests suites in subsequent branches.

To post a comment you must log in.
286. By Roberto Alsina

forgot half a test

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
Revision history for this message
Brian Curtin (brian.curtin) wrote :

looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/controlpanel/gui/qt/main/__init__.py'
2--- ubuntuone/controlpanel/gui/qt/main/__init__.py 2012-03-10 18:15:33 +0000
3+++ ubuntuone/controlpanel/gui/qt/main/__init__.py 2012-03-15 17:08:19 +0000
4@@ -63,7 +63,7 @@
5 # The following cannot be imported outside this function
6 # because u1trial already provides a reactor.
7
8- args = ['ubuntuone-installer'] + args[1:]
9+ args = ['ubuntuone-installer'] + args
10 app = UniqueApplication(args, "ubuntuone-control-panel")
11
12 # Install translator for standard dialogs.
13@@ -75,7 +75,10 @@
14
15 parser = parser_options()
16 # Use only the arguments that are not recognized by Qt
17- args = parser.parse_args(args=[unicode(x) for x in app.arguments()[1:]])
18+ # and after the name of the binary (bug #956143)
19+ arg_list = [unicode(arg) for arg in app.arguments()]
20+ bin_position = arg_list.index(sys.argv[0]) + 1
21+ args = parser.parse_args(args=arg_list[bin_position:])
22 switch_to = args.switch_to
23 minimized = args.minimized
24 with_icon = args.with_icon
25
26=== modified file 'ubuntuone/controlpanel/gui/qt/main/tests/test_main.py'
27--- ubuntuone/controlpanel/gui/qt/main/tests/test_main.py 2012-03-10 18:38:09 +0000
28+++ ubuntuone/controlpanel/gui/qt/main/tests/test_main.py 2012-03-15 17:08:19 +0000
29@@ -16,6 +16,8 @@
30
31 """Tests for the control panel's Qt main."""
32
33+import sys
34+
35 from PyQt4 import QtCore
36 from twisted.internet.defer import inlineCallbacks
37
38@@ -111,44 +113,52 @@
39 self.start = FakeStart()
40 self.patch(main, "UniqueApplication", self.app)
41 self.patch(main, "start", self.start)
42+ self.patch(main.source, "main_start", lambda app: None)
43 self.patch(QtCore, "QTranslator", lambda: self.translator)
44
45 def test_wm_class(self):
46 """Test that we set the 1st argument, used for WM_CLASS, correctly."""
47- main.main([])
48+ main.main([sys.argv[0]])
49 self.assertEqual(self.app.args,
50- (['ubuntuone-installer'], ('ubuntuone-control-panel',), {}))
51+ (['ubuntuone-installer', sys.argv[0]],
52+ ('ubuntuone-control-panel',), {}))
53
54 def test_title_not_fail(self):
55- """Ensure -title is removed before it gets to OptParser."""
56- main.main(["blah", "-title"])
57+ """Ensure -title is removed before it gets to argparse."""
58+ main.main([sys.argv[0], "-title"])
59 # Did not crash!
60
61+ def test_truncate_argv(self):
62+ """Ensure the binary name is not given to argparse."""
63+ main.main(["foo", "bar", sys.argv[0], "--minimized"])
64+ self.assertEqual(self.start.args[1],
65+ {'minimized': True, 'with_icon': False})
66+
67 def test_minimized_option(self):
68 """Ensure the --minimized option is parsed and passed correctly."""
69- main.main(["blah", "--minimized"])
70+ main.main([sys.argv[0], "--minimized"])
71 self.assertEqual(self.start.args[1],
72 {'minimized': True, 'with_icon': False})
73
74 def test_with_icon_option(self):
75 """Ensure the --minimized option is parsed and passed correctly."""
76- main.main(["blah", "--with-icon"])
77+ main.main([sys.argv[0], "--with-icon"])
78 self.assertEqual(self.start.args[1],
79 {'minimized': False, 'with_icon': True})
80
81 def test_style_loads(self):
82 """Ensure the stylesheet is loaded."""
83- main.main([])
84+ main.main([sys.argv[0]])
85 self.assertTrue(self.app.style)
86
87 def test_switch_to_option(self):
88 """Ensure the --switch-to option is parsed and passed correctly."""
89- main.main(["foobar", "--switch-to", "folders"])
90+ main.main([sys.argv[0], "--switch-to", "folders"])
91 self.assertEqual(self.start.window.tabname, "folders")
92
93 def test_translator(self):
94 """Ensure the Qt translator is loaded."""
95- main.main(["foo"])
96+ main.main([sys.argv[0]])
97 locale = unicode(QtCore.QLocale.system().name())
98 self.assertEqual(self.app.translator, self.translator)
99 self.assertEqual(self.translator.args, (("qt_" + locale,

Subscribers

People subscribed via source and target branches