Ejemplo n.º 1
0
    def test_make_index_w_distribution(self):
        import os
        import tarfile
        from compoze._compat import BytesIO
        tmpdir = self._makeTempdir()
        filename = os.path.join(tmpdir, 'testpackage-3.14.tar.gz')
        archive = tarfile.TarFile(filename, mode='w')
        buffer = BytesIO()
        buffer.writelines([
            b'Metadata-Version: 1.0\n',
            b'Name: testpackage\n',
            b'Version: 3.14\n',
        ])
        size = buffer.tell()
        buffer.seek(0)
        info = tarfile.TarInfo('PKG-INFO')
        info.size = size
        archive.addfile(info, buffer)
        archive.close()
        indexer = self._makeOne('--path=%s' % tmpdir)

        indexer.make_index()

        with open(os.path.join(tmpdir, 'simple', 'index.html')) as f:
            top = f.read()
        self.assertTrue('<h1>Package Index</h1>' in top)
        self.assertTrue(
            '<li><a href="testpackage">testpackage</a></li>' in top)
        with open(os.path.join(tmpdir, 'simple', 'testpackage',
                               'index.html')) as f:
            sub = f.read()
        self.assertTrue('<h1>testpackage Distributions</h1>' in sub)
        self.assertTrue('<li><a href="../../testpackage-3.14.tar.gz">'
                        'testpackage-3.14.tar.gz</a></li>' in sub)
Ejemplo n.º 2
0
 def add_setup(path):
     buffer = BytesIO()
     buffer.write(
         _DUMMY_SETUP.replace(b'testpackage', must_encode(path)))
     size = buffer.tell()
     buffer.seek(0)
     finfo = tarfile.TarInfo('%s/setup.py' % path)
     finfo.size = size
     archive.addfile(finfo, buffer)
Ejemplo n.º 3
0
    def test_make_index_w_distribution(self):
        import os
        import tarfile
        from compoze._compat import BytesIO

        tmpdir = self._makeTempdir()
        filename = os.path.join(tmpdir, "testpackage-3.14.tar.gz")
        archive = tarfile.TarFile(filename, mode="w")
        buffer = BytesIO()
        buffer.writelines([b"Metadata-Version: 1.0\n", b"Name: testpackage\n", b"Version: 3.14\n"])
        size = buffer.tell()
        buffer.seek(0)
        info = tarfile.TarInfo("PKG-INFO")
        info.size = size
        archive.addfile(info, buffer)
        archive.close()
        indexer = self._makeOne("--path=%s" % tmpdir)

        indexer.make_index()

        with open(os.path.join(tmpdir, "simple", "index.html")) as f:
            top = f.read()
        self.assertTrue("<h1>Package Index</h1>" in top)
        self.assertTrue('<li><a href="testpackage">testpackage</a></li>' in top)
        with open(os.path.join(tmpdir, "simple", "testpackage", "index.html")) as f:
            sub = f.read()
        self.assertTrue("<h1>testpackage Distributions</h1>" in sub)
        self.assertTrue('<li><a href="../../testpackage-3.14.tar.gz">' "testpackage-3.14.tar.gz</a></li>" in sub)
Ejemplo n.º 4
0
 def add_setup(path):
     buffer = BytesIO()
     buffer.write(_DUMMY_SETUP.replace(b"testpackage", must_encode(path)))
     size = buffer.tell()
     buffer.seek(0)
     finfo = tarfile.TarInfo("%s/setup.py" % path)
     finfo.size = size
     archive.addfile(finfo, buffer)
Ejemplo n.º 5
0
 def test__extractNameVersion_archive_no_egg_info_or_setup(self):
     import tarfile
     import tempfile
     from compoze._compat import BytesIO
     tested = self._makeOne()
     tfile = tempfile.NamedTemporaryFile(suffix='.tgz')
     archive = tarfile.TarFile(fileobj=tfile, mode='w')
     buffer = BytesIO()
     buffer.writelines([
         b'README\n',
     ])
     size = buffer.tell()
     buffer.seek(0)
     info = tarfile.TarInfo('README.txt')
     info.size = size
     archive.addfile(info, buffer)
     archive.close()
     tfile.flush()
     self.assertEqual(tested._extractNameVersion(tfile.name), (None, None))
Ejemplo n.º 6
0
 def test__extractNameVersion_archive_w_noout_setup(self):
     import tarfile
     import tempfile
     from compoze._compat import BytesIO
     tested = self._makeOne()
     tfile = tempfile.NamedTemporaryFile(suffix='.tgz')
     archive = tarfile.TarFile(fileobj=tfile, mode='w')
     dinfo = tarfile.TarInfo('testpackage')
     dinfo.type = tarfile.DIRTYPE
     dinfo.mode = 0o777
     archive.addfile(dinfo)
     buffer = BytesIO()
     buffer.write(_NOOUT_SETUP)
     size = buffer.tell()
     buffer.seek(0)
     finfo = tarfile.TarInfo('setup.py')
     finfo.size = size
     archive.addfile(finfo, buffer)
     archive.close()
     tfile.flush()
     self.assertEqual(tested._extractNameVersion(tfile.name), (None, None))
Ejemplo n.º 7
0
    def test__extractNameVersion_archive_w_pkg_info_version_first(self):
        import tarfile
        import tempfile
        from compoze._compat import BytesIO

        tested = self._makeOne()
        tfile = tempfile.NamedTemporaryFile(suffix=".tgz")
        archive = tarfile.TarFile(fileobj=tfile, mode="w")
        buffer = BytesIO()
        buffer.writelines([b"Metadata-Version: 1.0\n", b"Version: 3.14\n", b"Name: testpackage\n"])
        size = buffer.tell()
        buffer.seek(0)
        info = tarfile.TarInfo("testpackage.egg-info/PKG-INFO")
        info.size = size
        archive.addfile(info, buffer)
        archive.close()
        tfile.flush()
        self.assertEqual(tested._extractNameVersion(tfile.name), ("testpackage", "3.14"))
Ejemplo n.º 8
0
    def test__extractNameVersion_archive_no_egg_info_or_setup(self):
        import tarfile
        import tempfile
        from compoze._compat import BytesIO

        tested = self._makeOne()
        tfile = tempfile.NamedTemporaryFile(suffix=".tgz")
        archive = tarfile.TarFile(fileobj=tfile, mode="w")
        buffer = BytesIO()
        buffer.writelines([b"README\n"])
        size = buffer.tell()
        buffer.seek(0)
        info = tarfile.TarInfo("README.txt")
        info.size = size
        archive.addfile(info, buffer)
        archive.close()
        tfile.flush()
        self.assertEqual(tested._extractNameVersion(tfile.name), (None, None))
Ejemplo n.º 9
0
 def test__extractNameVersion_archive_w_pkg_info_version_first(self):
     import tarfile
     import tempfile
     from compoze._compat import BytesIO
     tested = self._makeOne()
     tfile = tempfile.NamedTemporaryFile(suffix='.tgz')
     archive = tarfile.TarFile(fileobj=tfile, mode='w')
     buffer = BytesIO()
     buffer.writelines([
         b'Metadata-Version: 1.0\n',
         b'Version: 3.14\n',
         b'Name: testpackage\n',
     ])
     size = buffer.tell()
     buffer.seek(0)
     info = tarfile.TarInfo('testpackage.egg-info/PKG-INFO')
     info.size = size
     archive.addfile(info, buffer)
     archive.close()
     tfile.flush()
     self.assertEqual(tested._extractNameVersion(tfile.name),
                      ('testpackage', '3.14'))
Ejemplo n.º 10
0
    def test__extractNameVersion_archive_w_noout_setup(self):
        import tarfile
        import tempfile
        from compoze._compat import BytesIO

        tested = self._makeOne()
        tfile = tempfile.NamedTemporaryFile(suffix=".tgz")
        archive = tarfile.TarFile(fileobj=tfile, mode="w")
        dinfo = tarfile.TarInfo("testpackage")
        dinfo.type = tarfile.DIRTYPE
        dinfo.mode = 0o777
        archive.addfile(dinfo)
        buffer = BytesIO()
        buffer.write(_NOOUT_SETUP)
        size = buffer.tell()
        buffer.seek(0)
        finfo = tarfile.TarInfo("setup.py")
        finfo.size = size
        archive.addfile(finfo, buffer)
        archive.close()
        tfile.flush()
        self.assertEqual(tested._extractNameVersion(tfile.name), (None, None))