33
44from __future__ import absolute_import
55
6- import json
76import os
87import subprocess
98from textwrap import dedent
@@ -179,7 +178,9 @@ def test_desktop_file(tmpdir):
179178 dedent (
180179 """\
181180 [Test]
182- Data={{"name": "{name}", "exe": "{exe}", "icon": "{icon}"}}
181+ name={name}
182+ exe={exe}
183+ icon={icon}
183184
184185 [Desktop Entry]
185186 Name=Slartibartfast
@@ -188,9 +189,9 @@ def test_desktop_file(tmpdir):
188189 )
189190 )
190191
191- icon = tmpdir .join ("file.ico" )
192+ icon_path = tmpdir .join ("file.ico" )
192193 icon_contents = "1/137"
193- with open (icon , "w" ) as fp :
194+ with open (icon_path , "w" ) as fp :
194195 fp .write (icon_contents )
195196
196197 run_pex_command (
@@ -206,29 +207,67 @@ def test_desktop_file(tmpdir):
206207 "eager" ,
207208 "--scie-only" ,
208209 "--scie-icon" ,
209- icon ,
210+ icon_path ,
210211 "--scie-desktop-file" ,
211212 desktop_file ,
212213 "--no-scie-prompt-desktop-install" ,
213214 ]
214215 ).assert_success ()
215216
216- xdg_data_home = safe_mkdir (tmpdir .join ("XDG_DATA_HOME" ))
217- scie_base = tmpdir .join ("nce" )
218- env = make_env (SCIE_BASE = scie_base , XDG_DATA_HOME = xdg_data_home )
219- assert b"| Moo! |" in subprocess .check_output (args = [scie , "Moo!" ], env = env )
217+ def assert_desktop_entry (
218+ scie_base , # type: str
219+ xdg_data_home , # type: str
220+ ):
221+ env = make_env (SCIE_BASE = scie_base , XDG_DATA_HOME = xdg_data_home )
222+ assert b"| Moo! |" in subprocess .check_output (args = [scie , "Moo!" ], env = env )
220223
221- parser = DesktopFileParser .create (os .path .join (xdg_data_home , "applications" , "cowsay.desktop" ))
222- assert "Slartibartfast" == parser .get ("Desktop Entry" , "Name" )
223- assert "DoesNotExist.png" == parser .get ("Desktop Entry" , "Icon" )
224+ parser = DesktopFileParser .create (
225+ os .path .join (xdg_data_home , "applications" , "cowsay.desktop" )
226+ )
227+ assert "Slartibartfast" == parser .get ("Desktop Entry" , "Name" )
228+ assert "DoesNotExist.png" == parser .get ("Desktop Entry" , "Icon" )
224229
225- data = json . loads ( parser .get ("Test " , "Data" ) )
226- assert parser . get ( "Desktop Entry" , "Exec" ) == data . pop ( "exe" )
227- assert "cowsay" == data . pop ( "name " )
230+ executable = parser .get ("Desktop Entry " , "Exec" )
231+ assert executable != scie
232+ assert scie == parser . get ( "Test" , "exe " )
228233
229- icon = data .pop ("icon" )
230- assert scie_base == commonpath ((scie_base , icon ))
231- with open (icon ) as fp :
232- assert icon_contents == fp .read ()
234+ def assert_quoting (string ):
235+ # type: (str) -> str
233236
234- assert not data
237+ if " " not in string :
238+ return string
239+
240+ prefix , unquoted , suffix = string .split ('"' )
241+ assert not prefix , "Expected {string} to be quoted but found prefix {prefix}." .format (
242+ string = string , prefix = prefix
243+ )
244+ assert not suffix , "Expected {string} to be quoted but found prefix {suffix}." .format (
245+ string = string , suffix = suffix
246+ )
247+ return unquoted
248+
249+ exe , arg = executable .split ()
250+ exe = assert_quoting (exe )
251+
252+ option , value = arg .split ("=" )
253+ assert "--launch" == option
254+ value = assert_quoting (value )
255+
256+ assert b"| Moo? |" in subprocess .check_output (
257+ args = [exe , "{option}={value}" .format (option = option , value = value )] + ["Moo?" ], env = env
258+ )
259+
260+ assert "cowsay" == parser .get ("Test" , "name" )
261+
262+ icon = parser .get ("Test" , "icon" )
263+ assert scie_base == commonpath ((scie_base , icon ))
264+ with open (icon ) as fp :
265+ assert icon_contents == fp .read ()
266+
267+ assert_desktop_entry (
268+ scie_base = tmpdir .join ("nce-no-space" ),
269+ xdg_data_home = safe_mkdir (tmpdir .join ("XDG_DATA_HOME" )),
270+ )
271+ assert_desktop_entry (
272+ scie_base = tmpdir .join ("nce-space" ), xdg_data_home = safe_mkdir (tmpdir .join ("XDG DATA HOME" ))
273+ )
0 commit comments