Commits

Anonymous committed e087258

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.

Comments (0)

Files changed (7)

src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/choxie/__init__.py

+# -*- coding: utf-8 -*-
+

src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/choxie/chocolate.py

+# -*- 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

src/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9/truffles.py

+# -*- coding: utf-8 -*-
+from choxie.chocolate import Chocolate
+
+class Truffle(Chocolate):
+    """A truffle."""

src/distutils2/_backport/tests/fake_dists/grammar-1.0a4/grammar/__init__.py

+# -*- coding: utf-8 -*-
+

src/distutils2/_backport/tests/fake_dists/grammar-1.0a4/grammar/utils.py

+# -*- coding: utf-8 -*-
+from random import randint
+
+def is_valid_grammar(sentence):
+    if randint(0, 10) < 2:
+        return False
+    else:
+        return True

src/distutils2/_backport/tests/fake_dists/towel_stuff-0.1/towel_stuff/__init__.py

+# -*- 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

src/distutils2/_backport/tests/test_pkgutil.py

 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"""
         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."""
         # 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()