6
6
import stat
7
7
import time
8
8
from typing import List , Tuple
9
+ from pathlib import Path
9
10
10
11
import pytest
11
12
from jaraco import path
12
13
14
+ from setuptools import errors
13
15
from setuptools .command .egg_info import (
14
- egg_info , manifest_maker , EggInfoDeprecationWarning , get_pkg_info_revision ,
16
+ EggInfoDeprecationWarning ,
17
+ egg_info ,
18
+ get_pkg_info_revision ,
19
+ manifest_maker ,
20
+ write_entries ,
15
21
)
16
22
from setuptools .dist import Distribution
17
23
@@ -24,6 +30,28 @@ class Environment(str):
24
30
pass
25
31
26
32
33
+ @pytest .fixture
34
+ def env ():
35
+ with contexts .tempdir (prefix = 'setuptools-test.' ) as env_dir :
36
+ env = Environment (env_dir )
37
+ os .chmod (env_dir , stat .S_IRWXU )
38
+ subs = 'home' , 'lib' , 'scripts' , 'data' , 'egg-base'
39
+ env .paths = dict (
40
+ (dirname , os .path .join (env_dir , dirname ))
41
+ for dirname in subs
42
+ )
43
+ list (map (os .mkdir , env .paths .values ()))
44
+ path .build ({
45
+ env .paths ['home' ]: {
46
+ '.pydistutils.cfg' : DALS ("""
47
+ [egg_info]
48
+ egg-base = %(egg-base)s
49
+ """ % env .paths )
50
+ }
51
+ })
52
+ yield env
53
+
54
+
27
55
class TestEggInfo :
28
56
29
57
setup_script = DALS ("""
@@ -51,27 +79,6 @@ def _extract_mv_version(pkg_info_lines: List[str]) -> Tuple[int, int]:
51
79
version_str = pkg_info_lines [0 ].split (' ' )[1 ]
52
80
return tuple (map (int , version_str .split ('.' )[:2 ]))
53
81
54
- @pytest .fixture
55
- def env (self ):
56
- with contexts .tempdir (prefix = 'setuptools-test.' ) as env_dir :
57
- env = Environment (env_dir )
58
- os .chmod (env_dir , stat .S_IRWXU )
59
- subs = 'home' , 'lib' , 'scripts' , 'data' , 'egg-base'
60
- env .paths = dict (
61
- (dirname , os .path .join (env_dir , dirname ))
62
- for dirname in subs
63
- )
64
- list (map (os .mkdir , env .paths .values ()))
65
- path .build ({
66
- env .paths ['home' ]: {
67
- '.pydistutils.cfg' : DALS ("""
68
- [egg_info]
69
- egg-base = %(egg-base)s
70
- """ % env .paths )
71
- }
72
- })
73
- yield env
74
-
75
82
def test_egg_info_save_version_info_setup_empty (self , tmpdir_cwd , env ):
76
83
"""
77
84
When the egg_info section is empty or not present, running
@@ -1084,3 +1091,27 @@ def test_egg_info_tag_only_once(self, tmpdir_cwd, env):
1084
1091
1085
1092
def test_get_pkg_info_revision_deprecated (self ):
1086
1093
pytest .warns (EggInfoDeprecationWarning , get_pkg_info_revision )
1094
+
1095
+
1096
+ class TestWriteEntries :
1097
+
1098
+ def test_invalid_entry_point (self , tmpdir_cwd , env ):
1099
+ dist = Distribution ({"name" : "foo" , "version" : "0.0.1" })
1100
+ dist .entry_points = {"foo" : "foo = invalid-identifier:foo" }
1101
+ cmd = dist .get_command_obj ("egg_info" )
1102
+ expected_msg = r"Problems to parse .*invalid-identifier.*"
1103
+ with pytest .raises (errors .OptionError , match = expected_msg ) as ex :
1104
+ write_entries (cmd , "entry_points" , "entry_points.txt" )
1105
+ assert "ensure entry-point follows the spec" in ex .value .args [0 ]
1106
+
1107
+ def test_valid_entry_point (self , tmpdir_cwd , env ):
1108
+ dist = Distribution ({"name" : "foo" , "version" : "0.0.1" })
1109
+ dist .entry_points = {
1110
+ "abc" : "foo = bar:baz" ,
1111
+ "def" : ["faa = bor:boz" ],
1112
+ }
1113
+ cmd = dist .get_command_obj ("egg_info" )
1114
+ write_entries (cmd , "entry_points" , "entry_points.txt" )
1115
+ content = Path ("entry_points.txt" ).read_text (encoding = "utf-8" )
1116
+ assert "[abc]\n foo = bar:baz\n " in content
1117
+ assert "[def]\n faa = bor:boz\n " in content
0 commit comments