1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
import os
import unittest
from copy import deepcopy
from pickle import dumps
from tempfile import TemporaryDirectory
from dhpython.depends import Dependencies
class FakeOptions:
def __init__(self, **kwargs):
opts = {
'depends': (),
'depends_section': (),
'guess_deps': False,
'recommends': (),
'recommends_section': (),
'requires': (),
'suggests': (),
'suggests_section': (),
'vrange': None,
'accept_upstream_versions': False,
}
opts.update(kwargs)
for k, v in opts.items():
setattr(self, k, v)
def prime_pydist(impl, pydist):
"""Fake the pydist data for impl. Returns a cleanup function"""
from dhpython.pydist import load
for name, entries in pydist.items():
if not isinstance(entries, list):
pydist[name] = entries = [entries]
for i, entry in enumerate(entries):
if isinstance(entry, str):
entries[i] = entry = {'dependency': entry}
entry.setdefault('name', name)
entry.setdefault('standard', '')
entry.setdefault('rules', [])
entry.setdefault('versions', set())
key = dumps(((impl,), {}))
load.cache[key] = pydist
return lambda: load.cache.pop(key)
class DependenciesTestCase(unittest.TestCase):
pkg = 'foo'
impl = 'cpython3'
pydist = {}
stats = {
'compile': False,
'egg-info': set(),
'ext_no_version': set(),
'ext_vers': set(),
'nsp.txt': set(),
'private_dirs': {},
'public_vers': set(),
'requires.txt': set(),
'shebangs': set(),
}
requires = {}
options = FakeOptions()
def setUp(self):
self.d = Dependencies(self.pkg, self.impl)
stats = deepcopy(self.stats)
if self.requires:
self.tempdir = TemporaryDirectory()
self.addCleanup(self.tempdir.cleanup)
old_wd = os.getcwd()
os.chdir(self.tempdir.name)
self.addCleanup(os.chdir, old_wd)
for fn, lines in self.requires.items():
os.makedirs(os.path.dirname(fn))
with open(fn, 'w') as f:
f.write('\n'.join(lines))
stats['requires.txt'].add(fn)
cleanup = prime_pydist(self.impl, self.pydist)
self.addCleanup(cleanup)
self.d.parse(stats, self.options)
class TestRequiresCPython3(DependenciesTestCase):
options = FakeOptions(guess_deps=True)
pydist = {
'bar': 'python3-bar',
'baz': {'dependency': 'python3-baz', 'standard': 'PEP386'},
'quux': {'dependency': 'python3-quux', 'standard': 'PEP386'},
}
requires = {
'debian/foo/usr/lib/python3/dist-packages/foo.egg-info/requires.txt': (
'bar',
'baz >= 1.0',
'quux',
),
}
def test_depends_on_bar(self):
self.assertIn('python3-bar', self.d.depends)
def test_depends_on_baz(self):
self.assertIn('python3-baz (>= 1.0)', self.d.depends)
class TestRequiresPyPy(DependenciesTestCase):
impl = 'pypy'
options = FakeOptions(guess_deps=True)
pydist = {
'bar': 'pypy-bar',
'baz': {'dependency': 'pypy-baz', 'standard': 'PEP386'},
'quux': {'dependency': 'pypy-quux', 'standard': 'PEP386'},
}
requires = {
'debian/foo/usr/lib/pypy/dist-packages/foo.egg-info/requires.txt': (
'bar',
'baz >= 1.0',
'quux',
)
}
def test_depends_on_bar(self):
self.assertIn('pypy-bar', self.d.depends)
def test_depends_on_baz(self):
self.assertIn('pypy-baz (>= 1.0)', self.d.depends)
class TestRequiresCompatible(DependenciesTestCase):
options = FakeOptions(guess_deps=True)
pydist = {
'bar': 'python3-bar',
'baz': {'dependency': 'python3-baz', 'standard': 'PEP386'},
'quux': {'dependency': 'python3-quux', 'standard': 'PEP386'},
}
requires = {
'debian/foo/usr/lib/python3/dist-packages/foo.egg-info/requires.txt': (
'bar',
'baz ~= 1.0',
'quux',
),
}
def test_depends_on_bar(self):
self.assertIn('python3-bar', self.d.depends)
def test_depends_on_baz(self):
self.assertIn('python3-baz (>= 1.0), python3-baz (<< 2)', self.d.depends)
|