[Python-checkins] distutils2: Adding package data for the fake distributions. Added logic in the

tarek.ziade python-checkins at python.org
Mon Apr 5 23:09:19 CEST 2010


tarek.ziade pushed e087258425a6 to distutils2:

http://hg.python.org/distutils2/rev/e087258425a6
changeset:   100:e087258425a6
user:        pumazi
date:        Wed Mar 31 11:49:10 2010 -0400
summary:     Adding package data for the fake distributions. Added logic in the Distribution.installed_files test to dynamically create the RECORD file because the locations will surely differ from system to system.
files:       src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/choxie/__init__.py, src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/choxie/chocolate.py, src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/truffles.py, src/distutils2/_backport/tests/fake_dists/grammar-1.0a4/grammar/__init__.py, src/distutils2/_backport/tests/fake_dists/grammar-1.0a4/grammar/utils.py, src/distutils2/_backport/tests/fake_dists/towel_stuff-0.1/towel_stuff/__init__.py, src/distutils2/_backport/tests/test_pkgutil.py

diff --git a/src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/choxie/__init__.py b/src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/choxie/__init__.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/choxie/__init__.py
@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+
diff --git a/src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/choxie/chocolate.py b/src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/choxie/chocolate.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/choxie/chocolate.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+from towel_stuff import Towel
+
+class Chocolate(object):
+    """A piece of chocolate."""
+
+    def wrap_with_towel(self):
+        towel = Towel()
+        towel.wrap(self)
+        return towel
diff --git a/src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/truffles.py b/src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/truffles.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/truffles.py
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+from choxie.chocolate import Chocolate
+
+class Truffle(Chocolate):
+    """A truffle."""
diff --git a/src/distutils2/_backport/tests/fake_dists/grammar-1.0a4/grammar/__init__.py b/src/distutils2/_backport/tests/fake_dists/grammar-1.0a4/grammar/__init__.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/_backport/tests/fake_dists/grammar-1.0a4/grammar/__init__.py
@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+
diff --git a/src/distutils2/_backport/tests/fake_dists/grammar-1.0a4/grammar/utils.py b/src/distutils2/_backport/tests/fake_dists/grammar-1.0a4/grammar/utils.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/_backport/tests/fake_dists/grammar-1.0a4/grammar/utils.py
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+from random import randint
+
+def is_valid_grammar(sentence):
+    if randint(0, 10) < 2:
+        return False
+    else:
+        return True
diff --git a/src/distutils2/_backport/tests/fake_dists/towel_stuff-0.1/towel_stuff/__init__.py b/src/distutils2/_backport/tests/fake_dists/towel_stuff-0.1/towel_stuff/__init__.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/_backport/tests/fake_dists/towel_stuff-0.1/towel_stuff/__init__.py
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+
+class Towel(object):
+    """A towel, that one should never be without."""
+
+    def __init__(self, color='tie-dye'):
+        self.color = color
+        self.wrapped_obj = None
+
+    def wrap(self, obj):
+        """Wrap an object up in our towel."""
+        self.wrapped_obj = obj
+
+    def unwrap(self):
+        """Unwrap whatever is in our towel and return whatever it is."""
+        obj = self.wrapped_obj
+        self.wrapped_obj = None
+        return obj
diff --git a/src/distutils2/_backport/tests/test_pkgutil.py b/src/distutils2/_backport/tests/test_pkgutil.py
--- a/src/distutils2/_backport/tests/test_pkgutil.py
+++ b/src/distutils2/_backport/tests/test_pkgutil.py
@@ -3,11 +3,15 @@
 import unittest2
 import sys
 import os
+import csv
+import hashlib
 
 from test.test_support import run_unittest, TESTFN
 
 import distutils2._backport.pkgutil
 
+# TODO Add a test for getting a distribution that is provided by another
+#   distribution.
 
 class TestPkgUtilDistribution(unittest2.TestCase):
     """Tests the pkgutil.Distribution class"""
@@ -31,6 +35,41 @@
         self.assertEqual(dist.metadata['version'], version)
         self.assertTrue(isinstance(dist.requested, type(bool())))
 
+    def test_installed_files(self):
+        """Test the iteration of installed files."""
+        name = 'choxie'
+        version = '2.0.0.9'
+        # We need to setup the RECORD file for this test case
+        fake_dists_path = os.path.join(os.path.dirname(__file__), 'fake_dists')
+        from distutils2._backport.pkgutil import distinfo_dirname
+        record_file = os.path.join(fake_dists_path,
+            distinfo_dirname(name, version), 'RECORD')
+        record_writer = csv.writer(open(record_file, 'w'), delimiter=',',
+            quoting=csv.QUOTE_NONE)
+        distinfo_location = os.path.join(fake_dists_path,
+            distinfo_dirname(name, version))
+        dist_location = distinfo_location.replace('.dist-info', '')
+
+        def get_hexdigest(file):
+            md5_hash = hashlib.md5()
+            md5_hash.update(open(file).read())
+            return md5_hash.hexdigest()
+        def record_pieces(file):
+            digest = get_hexdigest(file)
+            size = os.path.getsize(file)
+            return [file, digest, size]
+
+        for path, dirs, files in os.walk(dist_location):
+            for f in files:
+                record_writer.writerow(record_pieces(os.path.join(path, f)))
+        for file in ['INSTALLER', 'METADATA', 'REQUESTED']:
+            record_writer.writerow(record_pieces(
+                os.path.join(distinfo_location, file)))
+        record_writer.writerow([record_file])
+
+        # Test choxie's installed files
+        
+
 
 class TestPkgUtilFunctions(unittest2.TestCase):
     """Tests for the new functionality added in PEP 376."""
@@ -112,6 +151,10 @@
         # Verify partial name matching doesn't work
         self.assertEqual(None, get_distribution('towel'))
 
+    def test_get_file_users(path):
+        """Test to determine which distributions use a file."""
+        pass
+
 
 def test_suite():
     suite = unittest2.TestSuite()

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


More information about the Python-checkins mailing list