11import os
2+ import platform
23import sys
34import unittest
45
@@ -51,6 +52,10 @@ def todo_test_get(self):
5152 """Ensures get works as expected."""
5253 self .fail ()
5354
55+ @unittest .skipIf (
56+ platform .system () != "Windows" ,
57+ "scrap features are broken on non windows platforms" ,
58+ )
5459 def test_get__owned_empty_type (self ):
5560 """Ensures get works when there is no data of the requested type
5661 in the clipboard and the clipboard is owned by the pygame application.
@@ -95,7 +100,10 @@ def test_put__text(self):
95100
96101 self .assertEqual (scrap .get (pygame .SCRAP_TEXT ), b"Another String" )
97102
98- @unittest .skipIf ("pygame.image" not in sys .modules , "requires pygame.image module" )
103+ @unittest .skipIf (
104+ platform .system () != "Windows" ,
105+ "scrap features are broken on non windows platforms" ,
106+ )
99107 def test_put__bmp_image (self ):
100108 """Ensures put can place a BMP image into the clipboard."""
101109 sf = pygame .image .load (trunk_relative_path ("examples/data/asprite.bmp" ))
@@ -104,6 +112,10 @@ def test_put__bmp_image(self):
104112
105113 self .assertEqual (scrap .get (pygame .SCRAP_BMP ), expected_bytes )
106114
115+ @unittest .skipIf (
116+ platform .system () != "Windows" ,
117+ "scrap features are broken on non windows platforms" ,
118+ )
107119 def test_put (self ):
108120 """Ensures put can place data into the clipboard
109121 when using a user defined type identifier.
@@ -205,109 +217,5 @@ def test_lost__not_owned(self):
205217 self .assertTrue (lost )
206218
207219
208- class X11InteractiveTest (unittest .TestCase ):
209- __tags__ = ["ignore" , "subprocess_ignore" ]
210- try :
211- pygame .display .init ()
212- except Exception :
213- pass
214- else :
215- if pygame .display .get_driver () == "x11" :
216- __tags__ = ["interactive" ]
217- pygame .display .quit ()
218-
219- def test_issue_223 (self ):
220- """PATCH: pygame.scrap on X11, fix copying into PRIMARY selection
221-
222- Copying into theX11 PRIMARY selection (mouse copy/paste) would not
223- work due to a confusion between content type and clipboard type.
224-
225- """
226-
227- from pygame import display , event , freetype
228- from pygame .locals import KEYDOWN , QUIT , SCRAP_SELECTION , SCRAP_TEXT , K_y
229-
230- success = False
231- freetype .init ()
232- font = freetype .Font (None , 24 )
233- display .init ()
234- display .set_caption ("Interactive X11 Paste Test" )
235- screen = display .set_mode ((600 , 200 ))
236- screen .fill (pygame .Color ("white" ))
237- text = "Scrap put() succeeded."
238- msg = (
239- "Some text has been placed into the X11 clipboard."
240- " Please click the center mouse button in an open"
241- " text window to retrieve it."
242- '\n \n Did you get "{}"? (y/n)'
243- ).format (text )
244- word_wrap (screen , msg , font , 6 )
245- display .flip ()
246- event .pump ()
247- scrap .init ()
248- scrap .set_mode (SCRAP_SELECTION )
249- scrap .put (SCRAP_TEXT , text .encode ("UTF-8" ))
250- while True :
251- e = event .wait ()
252- if e .type == QUIT :
253- break
254- if e .type == KEYDOWN :
255- success = e .key == K_y
256- break
257- pygame .display .quit ()
258- self .assertTrue (success )
259-
260-
261- def word_wrap (surf , text , font , margin = 0 , color = (0 , 0 , 0 )):
262- font .origin = True
263- surf_width , surf_height = surf .get_size ()
264- width = surf_width - 2 * margin
265- height = surf_height - 2 * margin
266- line_spacing = int (1.25 * font .get_sized_height ())
267- x , y = margin , margin + line_spacing
268- space = font .get_rect (" " )
269- for word in iwords (text ):
270- if word == "\n " :
271- x , y = margin , y + line_spacing
272- else :
273- bounds = font .get_rect (word )
274- if x + bounds .width + bounds .x >= width :
275- x , y = margin , y + line_spacing
276- if x + bounds .width + bounds .x >= width :
277- raise ValueError ("word too wide for the surface" )
278- if y + bounds .height - bounds .y >= height :
279- raise ValueError ("text to long for the surface" )
280- font .render_to (surf , (x , y ), None , color )
281- x += bounds .width + space .width
282- return x , y
283-
284-
285- def iwords (text ):
286- # r"\n|[^ ]+"
287- #
288- head = 0
289- tail = head
290- end = len (text )
291- while head < end :
292- if text [head ] == " " :
293- head += 1
294- tail = head + 1
295- elif text [head ] == "\n " :
296- head += 1
297- yield "\n "
298- tail = head + 1
299- elif tail == end :
300- yield text [head :]
301- head = end
302- elif text [tail ] == "\n " :
303- yield text [head :tail ]
304- head = tail
305- elif text [tail ] == " " :
306- yield text [head :tail ]
307- head = tail
308- else :
309- tail += 1
310-
311-
312220if __name__ == "__main__" :
313221 unittest .main ()
0 commit comments