Anonymous avatar Anonymous committed 152780a

Use subprocess module instad of os.popen() for the libconfig and pkgconfig functions.
Fixed minor glitches in unix and msys build configurations.
Added basic sdl.audio and sdl.keyboard unittests.

Comments (0)

Files changed (10)

config/config_modules.py

 import os, sys
 from config import helpers
-from config import config_msys, config_unix, config_win, config_darwin
+from config import config_unix, config_win, config_darwin, config_msys
 from config.config_generic import Dependency
 
 OS_MODULES = {

config/config_msys.py

                 p = msys_obj.msys_to_windows (os.path.join(d, h))
                 if os.path.isfile(p):
                     found_header = True
-                else:
-                    found_header = False
         if not found_header:
             return False
 

config/config_unix.py

 def get_install_libs(cfg):
     return []
 
-
 class Dependency (config_generic.Dependency):
     _searchdirs = [ "/usr", "/usr/local" ]
     _incdirs = [ "include", "X11/include" ]
             for h in self.header_files:
                 if os.path.isfile(os.path.join(d, h)):
                     found_header = True
-                else:
-                    found_header = False
         if not found_header:
             return False
 

config/config_win.py

     _libdirs = [ "", "VisualC\\SDL\\Release", "VisualC\\Release", "Release",
                  "lib"]
     _libprefix = ""
-

config/libconfig.py

-import os
-from config import msys
+import subprocess
+from config import msys, helpers
+try:
+    msys_obj = msys.Msys (require_mingw=False)
+except:
+    msys_obj = None
+
+def run_command (cmd):
+    if msys.is_msys():
+        return msys_obj.run_shell_command (cmd)
+    else:
+        p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE)
+        output = p.communicate()[0]
+        if helpers.getversion()[0] >= 3:
+            output = str (output, "ascii")
+        return p.returncode, output
 
 def exec_config(libconfig, flags):
-    if msys.is_msys ():
-        pipe = os.popen ("sh %s %s " % (libconfig, flags), "r")
-    else:
-        pipe = os.popen ("%s %s " % (libconfig, flags), "r")
-    data = pipe.readline ().strip ()
-    pipe.close ()
-    return data.split ()
+    cmd = [libconfig, flags]
+    return run_command (cmd)[1].split ()
 
 def get_incdirs(libconfig):
     flags = exec_config (libconfig, "--cflags")
     return exec_config(libconfig, "--version")
 
 def has_libconfig(libconfig):
-    if msys.is_msys ():
-        return os.system ("sh %s --version" % libconfig) == 0
-    else:
-        return os.system ("%s --version > /dev/null 2>&1" % libconfig) == 0
+    cmd = [libconfig, "--version"]
+    return run_command (cmd)[0] == 0
 exports msys_raw_input, MsysException, Msys
 """
 
-from config import helpers
+#from config.helpers import *
 from config.msysio import raw_input_ as msys_raw_input, print_ as msys_print
 from config.msysio import is_msys
 import os
         The first list entry  must be the MSYS path name of a bash shell
         script file.
         """
-        
         args = [self.shell]
         if not self._is_msys:
             args.append('--login')
         args.extend(command)
         previous_cwd = os.getcwd()
         try:
-            return subprocess.Popen(args,
-                                    stdout=subprocess.PIPE,
-                                    env=self.environ).communicate()[0]
+            p = subprocess.Popen(args, stdout=subprocess.PIPE,
+                                 stderr=subprocess.PIPE,
+                                 env=self.environ)
+            output = p.communicate()[0]
+            return p.returncode, output
         finally:
-            time.sleep(3)  # Allow shell subprocesses to terminate.
+            #time.sleep(3)  # Allow shell subprocesses to terminate.
             os.chdir(previous_cwd)
 
 __all__ = ['Msys', 'msys_raw_input', 'msys_print', 'MsysException']

config/pkgconfig.py

-import os
-from config import msys
+import subprocess
+from config import msys, helpers
+try:
+    msys_obj = msys.Msys (require_mingw=False)
+except:
+    msys_obj = None
+
+def run_command (cmd):
+    if msys.is_msys():
+        return msys_obj.run_shell_command (cmd)
+    else:
+        p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE)
+        output = p.communicate()[0]
+        if helpers.getversion()[0] >= 3:
+            output = str (output, "ascii")
+        return p.returncode, output
 
 def exec_pkgconfig (package, flags, repl=None):
-    if msys.is_msys ():
-        pipe = os.popen ("sh pkg-config %s %s" % (flags, package), "r")
-    else:
-        pipe = os.popen ("pkg-config %s %s" % (flags, package), "r")
-    data = pipe.readline ().strip ()
-    pipe.close ()
+    cmd = ["pkg-config", flags, package]
+    data = run_command (cmd)[1]
     if data and repl:
         return data.replace (repl, "").split ()
     return data.split ()
     return exec_pkgconfig (package, "--modversion")
 
 def exists (package):
-    pipe = os.popen ("pkg-config --exists %s" % package, "r")
-    ret = pipe.close ()
-    return ret in (None, 0)
+    cmd = ["pkg-config", "--exists", package]
+    return run_command (cmd)[0] in (None, 0)
 
 def has_pkgconfig ():
-    if msys.is_msys():
-        return os.system ("sh pkg-config --version") == 0
-    else:
-        return os.system ("pkg-config --version > /dev/null 2>&1") == 0
+    cmd = ["pkg-config", "--version"]
+    return run_command (cmd)[0] == 0
+    return True
 from distutils.command.install_data import install_data
 import os, sys, glob, time, re
 import modules, cfg
-from config import *
+from config import helpers, msys, config_modules
 
 VERSION = "2.0.0"
 DEBUG = True

test/sdl_audio_test.py

+try:
+    import pygame2.test.pgunittest as unittest
+except:
+    import pgunittest as unittest
+
+import pygame2
+import pygame2.sdl.audio as audio
+import pygame2.sdl.constants as constants
+
+class SDLAudioTest (unittest.TestCase):
+    def test_pygame2_sdl_audio_init(self):
+
+        # __doc__ (as of 2009-05-13) for pygame2.sdl.audio.init:
+
+        # init () -> None
+        # 
+        # Initializes the audio subsystem of the SDL library.
+        self.assertEquals (audio.init (), None)
+
+    def test_pygame2_sdl_audio_quit(self):
+
+        # __doc__ (as of 2009-05-13) for pygame2.sdl.audio.quit:
+
+        # quit () -> None
+        # 
+        # Shuts down the audio subsystem of the SDL library.
+        # 
+        # quit () -> None  Shuts down the audio subsystem of the SDL library.
+        # After calling this function, you should not invoke any class, method
+        # or function related to the audio subsystem as they are likely to
+        # fail or might give unpredictable results.
+        self.assertEquals (audio.quit (), None)
+
+    def test_pygame2_sdl_audio_was_init(self):
+
+        # __doc__ (as of 2009-05-13) for pygame2.sdl.audio.was_init:
+
+        # was_init () -> bool
+        # 
+        # was_init () -> bool  Returns, whether the audio subsystem of the SDL
+        # library is initialized.
+
+        audio.quit ()
+        self.assertEquals (audio.was_init (), False)
+        audio.init ()
+        self.assertEquals (audio.was_init (), True)
+        audio.quit ()
+        self.assertEquals (audio.was_init (), False)

test/sdl_keyboard_test.py

+try:
+    import pygame2.test.pgunittest as unittest
+except:
+    import pgunittest as unittest
+
+import pygame2
+import pygame2.sdl.keyboard as keyboard
+import pygame2.sdl.constants as constants
+
+class SDLKeyboardTest (unittest.TestCase):
+    def test_pygame2_sdl_keyboard_enable_repeat(self):
+
+        # __doc__ (as of 2009-05-13) for pygame2.sdl.keyboard.enable_repeat:
+
+        # enable_repeat (delay, interval) -> None
+        # 
+        # Enables or disables the keyboard repeat rate.
+        # 
+        # enable_repeat (delay, interval) -> None  Enables or disables the
+        # keyboard repeat rate.  Enables or disables the keyboard repeat rate.
+        # delay specifies how long a key must be pressed before the repeat
+        # begins. interval is the speed with which it repeats. delay and
+        # interval are expressed as milliseconds. Thus, after the initial
+        # delay has passed, repeated KEYDOWN events are sent through the event
+        # queue, using the specified interval.  Setting delay to 0 will
+        # disable repeating completely.
+        # 
+        # Setting delay to 0 will disable repeating completely.
+        self.assert_ (keyboard.enable_repeat (0, 0) == None)
+        self.assert_ (keyboard.enable_repeat (1, 1) == None)
+        self.assert_ (keyboard.enable_repeat (900, 1000) == None)
+        self.assertRaises (ValueError, keyboard.enable_repeat, -1, -1)
+        self.assertRaises (ValueError, keyboard.enable_repeat,  1, -1)
+        self.assertRaises (ValueError, keyboard.enable_repeat, -1,  1)
+
+    def test_pygame2_sdl_keyboard_enable_unicode(self):
+
+        # __doc__ (as of 2009-05-13) for pygame2.sdl.keyboard.enable_unicode:
+
+        # enable_unicode ([enable]) -> bool
+        # 
+        # Enables or disables unicode input handling.
+        # 
+        # enable_unicode ([enable]) -> bool  Enables or disables unicode input
+        # handling.  Enables or disables unicode input handling. If the
+        # argument is omitted, the function will return the current unicode
+        # handling state.  By default unicode handling is enabled and for
+        # keyboard events, the *unicode* member of the event will be filled
+        # with the corresponding unicode character.
+        self.assert_ (keyboard.enable_unicode () == False)
+        self.assert_ (keyboard.enable_unicode (True) == False)
+        self.assert_ (keyboard.enable_unicode (False) == True)
+        self.assert_ (keyboard.enable_unicode (True) == False)
+        self.assert_ (keyboard.enable_unicode (True) == True)
+        self.assert_ (keyboard.enable_unicode () == True)
+        self.assert_ (keyboard.enable_unicode (False) == True)
+        self.assert_ (keyboard.enable_unicode (False) == False)
+        self.assert_ (keyboard.enable_unicode () == False)
+        
+    def test_pygame2_sdl_keyboard_get_key_name(self):
+
+        # __doc__ (as of 2009-05-13) for pygame2.sdl.keyboard.get_key_name:
+
+        # get_key_name (key) -> str
+        # 
+        # Get the descriptive name for a key constant.
+        self.assert_ (keyboard.get_key_name (constants.K_a) == 'a')
+        self.assert_ (keyboard.get_key_name (constants.K_b) == 'b')
+        self.assert_ (keyboard.get_key_name (constants.K_q) == 'q')
+        self.assert_ (keyboard.get_key_name (constants.K_LEFT) == 'left')
+        self.assert_ (keyboard.get_key_name (constants.K_PAGEUP) == 'page up')
+        self.assert_ (keyboard.get_key_name (constants.K_KP4) == '[4]')
+        self.assert_ (keyboard.get_key_name (constants.K_4) == '4')
+
+    def todo_test_pygame2_sdl_keyboard_get_mod_state(self):
+
+        # __doc__ (as of 2009-05-13) for pygame2.sdl.keyboard.get_mod_state:
+
+        # get_mod_state () -> state
+        # 
+        # Returns the current state of the modifier keys (CTRL, ALT, etc.).
+        # 
+        # get_mod_state () -> state  Returns the current state of the modifier
+        # keys (CTRL, ALT, etc.).  Returns a single integer representing a
+        # bitmask of all the modifier keys being held. Using bitwise operators
+        # you can test if specific shift keys are pressed, the state of the
+        # capslock button, and more.  The bitmask will consist of the various
+        # KMOD_* flags as specified in the constants.
+
+        self.fail() 
+
+    def test_pygame2_sdl_keyboard_get_repeat(self):
+
+        # __doc__ (as of 2009-05-13) for pygame2.sdl.keyboard.get_repeat:
+
+        # get_repeat () -> delay, interval
+        # 
+        # Gets the currently set keyboard repeat delay and interval.
+        keyboard.enable_repeat (0, 0)
+        self.assert_ (keyboard.get_repeat () == (0, 0))
+        keyboard.enable_repeat (10, 10)
+        self.assert_ (keyboard.get_repeat () == (10, 10))
+        keyboard.enable_repeat (5, 2)
+        self.assert_ (keyboard.get_repeat () == (5, 2))
+        keyboard.enable_repeat (0, 5)
+        self.assert_ (keyboard.get_repeat () == (0, 5))
+        keyboard.enable_repeat (7, 0)
+        self.assert_ (keyboard.get_repeat () == (7, 0))
+
+    def todo_test_pygame2_sdl_keyboard_get_state(self):
+
+        # __doc__ (as of 2009-05-13) for pygame2.sdl.keyboard.get_state:
+
+        # get_state () -> dict
+        # 
+        # Gets the current keyboard state.
+        # 
+        # get_state () -> dict  Gets the current keyboard state.  Gets a
+        # dictionary with the current keyboard state. The keys of the
+        # dictionary are the key constants, the boolean values of the
+        # dictionary indicate, whether a certain key is pressed or not.
+
+        self.fail() 
+
+    def todo_test_pygame2_sdl_keyboard_set_mod_state(self):
+
+        # __doc__ (as of 2009-05-13) for pygame2.sdl.keyboard.set_mod_state:
+
+        # set_mod_state (mod) -> None
+        # 
+        # Sets the current modifier key state.
+        # 
+        # set_mod_state (mod) -> None  Sets the current modifier key state.
+        # Sets the current modifier key state. mod has to be a bitwise OR'd
+        # combination of the KMOD_* flags as they are specified in the
+        # constants.
+
+        self.fail() 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.