[Python-checkins] distutils2: Add distutils2 data files glob and unittest.

tarek.ziade python-checkins at python.org
Wed Feb 16 22:23:56 CET 2011


tarek.ziade pushed 866f5fad7919 to distutils2:

http://hg.python.org/distutils2/rev/866f5fad7919
changeset:   1026:866f5fad7919
user:        FELD Boris <lothiraldan at gmail.com>
date:        Thu Jan 27 17:15:13 2011 +0100
summary:
  Add distutils2 data files glob and unittest.

files:
  distutils2/data/__init__.py
  distutils2/data/tools.py
  distutils2/tests/test_data_files.py

diff --git a/distutils2/data/__init__.py b/distutils2/data/__init__.py
new file mode 100644
--- /dev/null
+++ b/distutils2/data/__init__.py
@@ -0,0 +1,3 @@
+"""distutils2.data
+
+contains tools for processing data files paths."""
\ No newline at end of file
diff --git a/distutils2/data/tools.py b/distutils2/data/tools.py
new file mode 100644
--- /dev/null
+++ b/distutils2/data/tools.py
@@ -0,0 +1,12 @@
+from glob import glob
+
+def check_glob(ressources):
+    correspondence = {}
+    for (path_glob,category) in ressources:
+        filepaths = glob(path_glob)
+        for filepath in filepaths:
+            if not filepath in correspondence:
+                correspondence[filepath] = []
+            if not category in correspondence[filepath]:
+                correspondence[filepath].append(category)
+    return correspondence
\ No newline at end of file
diff --git a/distutils2/tests/test_data_files.py b/distutils2/tests/test_data_files.py
new file mode 100644
--- /dev/null
+++ b/distutils2/tests/test_data_files.py
@@ -0,0 +1,58 @@
+# -*- encoding: utf-8 -*-
+"""Tests for distutils.data."""
+import os
+import sys
+from StringIO import StringIO
+
+from distutils2.tests import unittest, support, run_unittest
+from distutils2.data.tools import check_glob
+
+class DataFilesTestCase(support.TempdirManager,
+                            support.LoggingCatcher,
+                            unittest.TestCase):
+                            
+    def setUp(self):
+        super(DataFilesTestCase, self).setUp()
+        self.addCleanup(setattr, sys, 'stdout', sys.stdout)
+        self.addCleanup(setattr, sys, 'stderr', sys.stderr)
+        self.addCleanup(os.chdir, os.getcwd())
+       
+    def test_simple_check_glob(self):
+        tempdir = self.mkdtemp()
+        os.chdir(tempdir)
+        self.write_file('coucou.tpl', '')
+        category = '{data}'
+        self.assertEquals(
+            check_glob([('*.tpl', category)]),
+            {'coucou.tpl' : [category]})
+    
+    def test_multiple_glob_same_category(self):
+        tempdir = self.mkdtemp()
+        os.chdir(tempdir)
+        os.mkdir('scripts')
+        path = os.path.join('scripts', 'script.bin')
+        self.write_file(path, '')
+        category = '{appdata}'
+        self.assertEquals(
+            check_glob(
+                [('**/*.bin', category), ('scripts/*', category)]),
+                {path : [category]})
+    
+    def test_multiple_glob_different_category(self):
+        tempdir = self.mkdtemp()
+        os.chdir(tempdir)
+        os.mkdir('scripts')
+        path = os.path.join('scripts', 'script.bin')
+        self.write_file(path, '')
+        category_1 = '{appdata}'
+        category_2 = '{appscript}'
+        self.assertEquals(
+            check_glob(
+                [('**/*.bin', category_1), ('scripts/*', category_2)]),
+                {path : [category_1, category_2]})
+            
+def test_suite():
+    return unittest.makeSuite(DataFilesTestCase)
+
+if __name__ == '__main__':
+    run_unittest(test_suite())
\ No newline at end of file

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list