2012-03-26 00:23:28 +02:00
|
|
|
#! /usr/bin/env py.test
|
2016-01-17 21:57:16 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-03-26 00:23:28 +02:00
|
|
|
|
|
|
|
import pytest
|
2015-09-16 23:54:41 +02:00
|
|
|
from pypiserver import __main__, core
|
|
|
|
import logging
|
2012-03-26 00:23:28 +02:00
|
|
|
|
2014-11-15 02:37:40 +01:00
|
|
|
## Enable logging to detect any problems with it
|
|
|
|
##
|
2015-09-15 19:53:59 +02:00
|
|
|
__main__.init_logging(level=logging.NOTSET)
|
2014-11-15 02:37:40 +01:00
|
|
|
|
2012-03-26 00:23:28 +02:00
|
|
|
|
|
|
|
files = [
|
|
|
|
("pytz-2012b.tar.bz2", "pytz", "2012b"),
|
|
|
|
("pytz-2012b.tgz", "pytz", "2012b"),
|
2012-03-26 00:42:16 +02:00
|
|
|
("pytz-2012b.ZIP", "pytz", "2012b"),
|
2016-01-17 21:57:16 +01:00
|
|
|
("pytz-2012a.zip", "pytz", "2012a"),
|
2012-03-26 00:42:16 +02:00
|
|
|
("gevent-1.0b1.win32-py2.6.exe", "gevent", "1.0b1"),
|
|
|
|
("gevent-1.0b1.win32-py2.7.msi", "gevent", "1.0b1"),
|
|
|
|
("greenlet-0.3.4-py3.1-win-amd64.egg", "greenlet", "0.3.4"),
|
|
|
|
("greenlet-0.3.4.win-amd64-py3.2.exe", "greenlet", "0.3.4"),
|
|
|
|
("greenlet-0.3.4-py3.2-win32.egg", "greenlet", "0.3.4"),
|
|
|
|
("greenlet-0.3.4-py2.7-linux-x86_64.egg", "greenlet", "0.3.4"),
|
2012-03-26 01:05:11 +02:00
|
|
|
("pep8-0.6.0.zip", "pep8", "0.6.0"),
|
2013-07-19 12:42:36 +02:00
|
|
|
("ABC12-34_V1X-1.2.3.zip", "ABC12-34_V1X", "1.2.3"),
|
2013-07-19 17:00:20 +02:00
|
|
|
("A100-200-XYZ-1.2.3.zip", "A100-200-XYZ", "1.2.3"),
|
|
|
|
("flup-1.0.3.dev-20110405.tar.gz", "flup", "1.0.3.dev-20110405"),
|
|
|
|
("package-1.0.0-alpha.1.zip", "package", "1.0.0-alpha.1"),
|
|
|
|
("package-1.3.7+build.11.e0f985a.zip", "package", "1.3.7+build.11.e0f985a"),
|
|
|
|
("package-v1.8.1.301.ga0df26f.zip", "package", "v1.8.1.301.ga0df26f"),
|
|
|
|
("package-2013.02.17.dev123.zip", "package", "2013.02.17.dev123"),
|
|
|
|
("package-20000101.zip", "package", "20000101"),
|
|
|
|
("flup-123-1.0.3.dev-20110405.tar.gz", "flup-123", "1.0.3.dev-20110405"),
|
|
|
|
("package-123-1.0.0-alpha.1.zip", "package-123", "1.0.0-alpha.1"),
|
|
|
|
("package-123-1.3.7+build.11.e0f985a.zip", "package-123", "1.3.7+build.11.e0f985a"),
|
|
|
|
("package-123-v1.8.1.301.ga0df26f.zip", "package-123", "v1.8.1.301.ga0df26f"),
|
|
|
|
("package-123-2013.02.17.dev123.zip", "package-123", "2013.02.17.dev123"),
|
|
|
|
("package-123-20000101.zip", "package-123", "20000101"),
|
2013-07-22 21:24:29 +02:00
|
|
|
("pyelasticsearch-0.5-brainbot-1-20130712.zip", "pyelasticsearch", "0.5-brainbot-1-20130712"),
|
2014-01-19 21:55:14 +01:00
|
|
|
("pywin32-217-cp27-none-win32.whl", "pywin32", "217"),
|
2014-01-20 21:37:52 +01:00
|
|
|
("pywin32-217-55-cp27-none-win32.whl", "pywin32", "217-55"),
|
2014-01-19 21:55:14 +01:00
|
|
|
("pywin32-217.1-cp27-none-win32.whl", "pywin32", "217.1"),
|
2013-07-19 17:00:20 +02:00
|
|
|
("package.zip", "package", ""),
|
2015-08-05 02:55:34 +02:00
|
|
|
("package-name-0.0.1.dev0.linux-x86_64.tar.gz", "package-name", "0.0.1.dev0"),
|
|
|
|
("package-name-0.0.1.dev0.macosx-10.10-intel.tar.gz", "package-name", "0.0.1.dev0"),
|
|
|
|
("package-name-0.0.1.alpha.1.win-amd64-py3.2.exe", "package-name", "0.0.1.alpha.1"),
|
2016-01-17 21:57:16 +01:00
|
|
|
("pkg-3!1.0-0.1.tgz", 'pkg-3!1.0', '0.1'), # TO BE FIXED
|
|
|
|
("pkg-3!1+.0-0.1.tgz", 'pkg-3!1+.0', '0.1'), # TO BE FIXED
|
|
|
|
|
|
|
|
("a-γρεεκ-package-1.0", None, None),
|
|
|
|
("some/pkg-1.0", None, None),
|
2013-07-19 17:00:20 +02:00
|
|
|
]
|
2012-03-26 00:23:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(("filename", "pkgname", "version"), files)
|
|
|
|
def test_guess_pkgname_and_version(filename, pkgname, version):
|
2016-01-17 21:57:16 +01:00
|
|
|
if pkgname is None:
|
|
|
|
exp = None
|
|
|
|
else:
|
|
|
|
exp = (pkgname, version)
|
|
|
|
assert core.guess_pkgname_and_version(filename) == exp
|
2014-01-20 21:37:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_listdir_bad_name(tmpdir):
|
|
|
|
tmpdir.join("foo.whl").ensure()
|
|
|
|
res = list(core.listdir(tmpdir.strpath))
|
|
|
|
assert res == []
|
2015-12-20 00:42:44 +01:00
|
|
|
|
|
|
|
hashes = [
|
|
|
|
('sha256', 'e3b0c44298fc1c149afbf4c8996fb924'), # empty-sha256
|
|
|
|
('md5', 'd41d8cd98f00b204e9800998ecf8427e'), # empty-md5
|
|
|
|
]
|
|
|
|
@pytest.mark.parametrize(("algo", "digest"), hashes)
|
|
|
|
def test_hashfile(tmpdir, algo, digest):
|
|
|
|
f = tmpdir.join("empty")
|
|
|
|
f.ensure()
|
|
|
|
assert core.digest_file(f.strpath, algo) == digest
|