Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: recipe_engine/third_party/setuptools/tests/test_dist_info.py

Issue 1344583003: Recipe package system. (Closed) Base URL: git@github.com:luci/recipes-py.git@master
Patch Set: Recompiled proto Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 """Test .dist-info style distributions.
2 """
3 import os
4 import shutil
5 import tempfile
6 import unittest
7 import textwrap
8
9 try:
10 import ast
11 except:
12 pass
13
14 import pkg_resources
15
16 from setuptools.tests.py26compat import skipIf
17
18 def DALS(s):
19 "dedent and left-strip"
20 return textwrap.dedent(s).lstrip()
21
22 class TestDistInfo(unittest.TestCase):
23
24 def test_distinfo(self):
25 dists = {}
26 for d in pkg_resources.find_distributions(self.tmpdir):
27 dists[d.project_name] = d
28
29 assert len(dists) == 2, dists
30
31 unversioned = dists['UnversionedDistribution']
32 versioned = dists['VersionedDistribution']
33
34 assert versioned.version == '2.718' # from filename
35 assert unversioned.version == '0.3' # from METADATA
36
37 @skipIf('ast' not in globals(),
38 "ast is used to test conditional dependencies (Python >= 2.6)")
39 def test_conditional_dependencies(self):
40 requires = [pkg_resources.Requirement.parse('splort==4'),
41 pkg_resources.Requirement.parse('quux>=1.1')]
42
43 for d in pkg_resources.find_distributions(self.tmpdir):
44 self.assertEqual(d.requires(), requires[:1])
45 self.assertEqual(d.requires(extras=('baz',)), requires)
46 self.assertEqual(d.extras, ['baz'])
47
48 def setUp(self):
49 self.tmpdir = tempfile.mkdtemp()
50 versioned = os.path.join(self.tmpdir,
51 'VersionedDistribution-2.718.dist-info')
52 os.mkdir(versioned)
53 metadata_file = open(os.path.join(versioned, 'METADATA'), 'w+')
54 try:
55 metadata_file.write(DALS(
56 """
57 Metadata-Version: 1.2
58 Name: VersionedDistribution
59 Requires-Dist: splort (4)
60 Provides-Extra: baz
61 Requires-Dist: quux (>=1.1); extra == 'baz'
62 """))
63 finally:
64 metadata_file.close()
65 unversioned = os.path.join(self.tmpdir,
66 'UnversionedDistribution.dist-info')
67 os.mkdir(unversioned)
68 metadata_file = open(os.path.join(unversioned, 'METADATA'), 'w+')
69 try:
70 metadata_file.write(DALS(
71 """
72 Metadata-Version: 1.2
73 Name: UnversionedDistribution
74 Version: 0.3
75 Requires-Dist: splort (==4)
76 Provides-Extra: baz
77 Requires-Dist: quux (>=1.1); extra == 'baz'
78 """))
79 finally:
80 metadata_file.close()
81
82 def tearDown(self):
83 shutil.rmtree(self.tmpdir)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698