-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathutils.py
More file actions
140 lines (112 loc) · 2.74 KB
/
utils.py
File metadata and controls
140 lines (112 loc) · 2.74 KB
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
import os
from contextlib import contextmanager
from io import BytesIO
from pathlib import Path
from random import sample
from unittest.mock import Mock, patch
import pkg_resources
from rpdk.core.project import Project
CONTENTS_UTF8 = "💣"
NAMES = [
"Apple",
"Apricot",
"Avocado",
"Banana",
"Boysenberry",
"Blueberry",
"Cherry",
"Cantaloupe",
"Clementine",
"Cucumber",
"Date",
"Dewberry",
"DragonFruit",
"Elderberry",
"Fig",
"Grapefruit",
"Grape",
"Gooseberry",
"Guava",
"Kiwi",
"Kumquat",
"Lime",
"Lemon",
"Lychee",
"Loquat",
"Mango",
"Mandarin",
"Mulberry",
"Melon",
"Nectarine",
"Olive",
"Orange",
"Papaya",
"Persimmon",
"Peach",
"Pomegranate",
"Pineapple",
"Raspberry",
"Strawberry",
"Tomato",
"Tangerine",
"Watermelon",
]
def random_type_name():
return "Test::{0}::{1}".format(*sample(NAMES, 2))
def random_name():
return "-".join(sample(NAMES, 3))
@contextmanager
def chdir(path):
old = os.getcwd()
os.chdir(path)
yield path
os.chdir(old)
def add_dummy_language_plugin():
distribution = pkg_resources.Distribution(__file__)
entry_point = pkg_resources.EntryPoint.parse(
"dummy = rpdk.dummy:DummyLanguagePlugin", dist=distribution
)
distribution._ep_map = { # pylint: disable=protected-access
"rpdk.v1.languages": {"dummy": entry_point}
}
pkg_resources.working_set.add(distribution)
def get_mock_project():
mock_project = Mock(spec=Project)
mock_project.load_settings.side_effect = FileNotFoundError
mock_project.settings_path = ""
mock_project.root = Path(".")
patch_project = patch("rpdk.core.init.Project", return_value=mock_project)
return (mock_project, patch_project)
def get_args(language=None, type_name=None):
args = Mock(
spec_set=[
"language",
"type_name",
]
)
args.language = language
args.type_name = type_name
return args
def dummy_parser():
def dummy_subparser(subparsers, parents):
parser = subparsers.add_parser(
"dummy",
description="""This sub command generates IDE and build
files for the Dummy plugin""",
parents=parents,
)
parser.set_defaults(language="dummy")
parser.add_argument(
"-d",
"--dummy",
action="store_true",
help="Dummy boolean to test if parser is loaded correctly",
)
return parser
return dummy_subparser
class UnclosingBytesIO(BytesIO):
_was_closed = False
def close(self):
self._was_closed = True
def _close(self):
super().close()