|
19 | 19 |
|
20 | 20 | PYTHON = sys.version_info[0] # e.g. 2 or 3 |
21 | 21 |
|
| 22 | +self = sys.modules[__name__] |
| 23 | + |
| 24 | + |
| 25 | +def setup(): |
| 26 | + self.tempdir = tempfile.mkdtemp() |
| 27 | + |
| 28 | + |
| 29 | +def teardown(): |
| 30 | + shutil.rmtree(self.tempdir) |
| 31 | + |
22 | 32 |
|
23 | 33 | @contextlib.contextmanager |
24 | 34 | def pyqt4(): |
@@ -123,53 +133,50 @@ def test_vendoring(): |
123 | 133 |
|
124 | 134 | project/ |
125 | 135 | vendor/ |
126 | | - __init__.py |
127 | 136 | __init__.py |
| 137 | + __init__.py |
128 | 138 |
|
129 | 139 | """ |
130 | 140 |
|
131 | | - dirname = os.path.dirname(__file__) |
132 | | - tempdir = tempfile.mkdtemp() |
133 | | - |
134 | | - try: |
135 | | - project = os.path.join(tempdir, "myproject") |
136 | | - vendor = os.path.join(tempdir, "myproject", "vendor") |
137 | | - |
138 | | - os.makedirs(vendor) |
139 | | - |
140 | | - # Make packages out of folders |
141 | | - with open(os.path.join(project, "__init__.py"), "w") as f: |
142 | | - f.write("from .vendor.Qt import QtWidgets") |
143 | | - |
144 | | - with open(os.path.join(vendor, "__init__.py"), "w") as f: |
145 | | - pass |
146 | | - |
147 | | - shutil.copy(os.path.join(dirname, "Qt.py"), |
148 | | - os.path.join(vendor, "Qt.py")) |
149 | | - |
150 | | - print("Testing relative import..") |
151 | | - assert subprocess.call( |
152 | | - ["python", "-c", "import myproject"], |
153 | | - cwd=tempdir, |
154 | | - env={} |
155 | | - ) == 0 |
156 | | - |
157 | | - print("Testing absolute import..") |
158 | | - assert subprocess.call( |
159 | | - ["python", "-c", "from myproject.vendor.Qt import QtWidgets"], |
160 | | - cwd=tempdir, |
161 | | - env={} |
162 | | - ) == 0 |
163 | | - |
164 | | - print("Testing direct import..") |
165 | | - assert subprocess.call( |
166 | | - ["python", "-c", "import myproject.vendor.Qt"], |
167 | | - cwd=tempdir, |
168 | | - env={} |
169 | | - ) == 0 |
170 | | - |
171 | | - finally: |
172 | | - shutil.rmtree(tempdir) |
| 141 | + project = os.path.join(self.tempdir, "myproject") |
| 142 | + vendor = os.path.join(project, "vendor") |
| 143 | + |
| 144 | + os.makedirs(vendor) |
| 145 | + |
| 146 | + # Make packages out of folders |
| 147 | + with open(os.path.join(project, "__init__.py"), "w") as f: |
| 148 | + f.write("from .vendor.Qt import QtWidgets") |
| 149 | + |
| 150 | + with open(os.path.join(vendor, "__init__.py"), "w") as f: |
| 151 | + f.write("\n") |
| 152 | + |
| 153 | + # Copy real Qt.py into myproject |
| 154 | + shutil.copy(os.path.join(os.path.dirname(__file__), "Qt.py"), |
| 155 | + os.path.join(vendor, "Qt.py")) |
| 156 | + |
| 157 | + print("Testing relative import..") |
| 158 | + assert subprocess.call( |
| 159 | + ["python", "-c", "import myproject"], |
| 160 | + cwd=self.tempdir, |
| 161 | + stdout=subprocess.PIPE, # With nose process isolation, buffer can |
| 162 | + stderr=subprocess.STDOUT, # easily get full and throw an error. |
| 163 | + ) == 0 |
| 164 | + |
| 165 | + print("Testing absolute import..") |
| 166 | + assert subprocess.call( |
| 167 | + ["python", "-c", "from myproject.vendor.Qt import QtWidgets"], |
| 168 | + cwd=self.tempdir, |
| 169 | + stdout=subprocess.PIPE, |
| 170 | + stderr=subprocess.STDOUT, |
| 171 | + ) == 0 |
| 172 | + |
| 173 | + print("Testing direct import..") |
| 174 | + assert subprocess.call( |
| 175 | + ["python", "-c", "import myproject.vendor.Qt"], |
| 176 | + cwd=self.tempdir, |
| 177 | + stdout=subprocess.PIPE, |
| 178 | + stderr=subprocess.STDOUT, |
| 179 | + ) == 0 |
173 | 180 |
|
174 | 181 |
|
175 | 182 | if PYTHON == 2: |
|
0 commit comments