Best Python code snippet using tox_python
test_build_meta.py
Source:test_build_meta.py
...117 def test_get_requires_for_build_wheel(self, build_backend):118 actual = build_backend.get_requires_for_build_wheel()119 expected = ['six', 'wheel']120 assert sorted(actual) == sorted(expected)121 def test_get_requires_for_build_sdist(self, build_backend):122 actual = build_backend.get_requires_for_build_sdist()123 expected = ['six']124 assert sorted(actual) == sorted(expected)125 def test_build_wheel(self, build_backend):126 dist_dir = os.path.abspath('pip-wheel')127 os.makedirs(dist_dir)128 wheel_name = build_backend.build_wheel(dist_dir)129 assert os.path.isfile(os.path.join(dist_dir, wheel_name))130 def test_build_sdist(self, build_backend):131 dist_dir = os.path.abspath('pip-sdist')132 os.makedirs(dist_dir)133 sdist_name = build_backend.build_sdist(dist_dir)134 assert os.path.isfile(os.path.join(dist_dir, sdist_name))135 def test_prepare_metadata_for_build_wheel(self, build_backend):136 dist_dir = os.path.abspath('pip-dist-info')137 os.makedirs(dist_dir)138 dist_info = build_backend.prepare_metadata_for_build_wheel(dist_dir)139 assert os.path.isfile(os.path.join(dist_dir, dist_info, 'METADATA'))140 @py2_only141 def test_prepare_metadata_for_build_wheel_with_str(self, build_backend):142 dist_dir = os.path.abspath(str('pip-dist-info'))143 os.makedirs(dist_dir)144 dist_info = build_backend.prepare_metadata_for_build_wheel(dist_dir)145 assert os.path.isfile(os.path.join(dist_dir, dist_info, 'METADATA'))146 def test_build_sdist_explicit_dist(self, build_backend):147 # explicitly specifying the dist folder should work148 # the folder sdist_directory and the ``--dist-dir`` can be the same149 dist_dir = os.path.abspath('dist')150 sdist_name = build_backend.build_sdist(dist_dir)151 assert os.path.isfile(os.path.join(dist_dir, sdist_name))152 def test_build_sdist_version_change(self, build_backend):153 sdist_into_directory = os.path.abspath("out_sdist")154 os.makedirs(sdist_into_directory)155 sdist_name = build_backend.build_sdist(sdist_into_directory)156 assert os.path.isfile(os.path.join(sdist_into_directory, sdist_name))157 # if the setup.py changes subsequent call of the build meta158 # should still succeed, given the159 # sdist_directory the frontend specifies is empty160 setup_loc = os.path.abspath("setup.py")161 if not os.path.exists(setup_loc):162 setup_loc = os.path.abspath("setup.cfg")163 with open(setup_loc, 'rt') as file_handler:164 content = file_handler.read()165 with open(setup_loc, 'wt') as file_handler:166 file_handler.write(167 content.replace("version='0.0.0'", "version='0.0.1'"))168 shutil.rmtree(sdist_into_directory)169 os.makedirs(sdist_into_directory)170 sdist_name = build_backend.build_sdist("out_sdist")171 assert os.path.isfile(172 os.path.join(os.path.abspath("out_sdist"), sdist_name))173 def test_build_sdist_setup_py_exists(self, tmpdir_cwd):174 # If build_sdist is called from a script other than setup.py,175 # ensure setup.py is included176 build_files(defns[0])177 build_backend = self.get_build_backend()178 targz_path = build_backend.build_sdist("temp")179 with tarfile.open(os.path.join("temp", targz_path)) as tar:180 assert any('setup.py' in name for name in tar.getnames())181 def test_build_sdist_setup_py_manifest_excluded(self, tmpdir_cwd):182 # Ensure that MANIFEST.in can exclude setup.py183 files = {184 'setup.py': DALS("""185 __import__('setuptools').setup(186 name='foo',187 version='0.0.0',188 py_modules=['hello']189 )"""),190 'hello.py': '',191 'MANIFEST.in': DALS("""192 exclude setup.py193 """)194 }195 build_files(files)196 build_backend = self.get_build_backend()197 targz_path = build_backend.build_sdist("temp")198 with tarfile.open(os.path.join("temp", targz_path)) as tar:199 assert not any('setup.py' in name for name in tar.getnames())200 def test_build_sdist_builds_targz_even_if_zip_indicated(self, tmpdir_cwd):201 files = {202 'setup.py': DALS("""203 __import__('setuptools').setup(204 name='foo',205 version='0.0.0',206 py_modules=['hello']207 )"""),208 'hello.py': '',209 'setup.cfg': DALS("""210 [sdist]211 formats=zip212 """)213 }214 build_files(files)215 build_backend = self.get_build_backend()216 build_backend.build_sdist("temp")217 _relative_path_import_files = {218 'setup.py': DALS("""219 __import__('setuptools').setup(220 name='foo',221 version=__import__('hello').__version__,222 py_modules=['hello']223 )"""),224 'hello.py': '__version__ = "0.0.0"',225 'setup.cfg': DALS("""226 [sdist]227 formats=zip228 """)229 }230 def test_build_sdist_relative_path_import(self, tmpdir_cwd):231 build_files(self._relative_path_import_files)232 build_backend = self.get_build_backend()233 with pytest.raises(ImportError):234 build_backend.build_sdist("temp")235 @pytest.mark.parametrize('setup_literal, requirements', [236 ("'foo'", ['foo']),237 ("['foo']", ['foo']),238 (r"'foo\n'", ['foo']),239 (r"'foo\n\n'", ['foo']),240 ("['foo', 'bar']", ['foo', 'bar']),241 (r"'# Has a comment line\nfoo'", ['foo']),242 (r"'foo # Has an inline comment'", ['foo']),243 (r"'foo \\\n >=3.0'", ['foo>=3.0']),244 (r"'foo\nbar'", ['foo', 'bar']),245 (r"'foo\nbar\n'", ['foo', 'bar']),246 (r"['foo\n', 'bar\n']", ['foo', 'bar']),247 ])248 @pytest.mark.parametrize('use_wheel', [True, False])249 def test_setup_requires(self, setup_literal, requirements, use_wheel,250 tmpdir_cwd):251 files = {252 'setup.py': DALS("""253 from setuptools import setup254 setup(255 name="qux",256 version="0.0.0",257 py_modules=["hello.py"],258 setup_requires={setup_literal},259 )260 """).format(setup_literal=setup_literal),261 'hello.py': DALS("""262 def run():263 print('hello')264 """),265 }266 build_files(files)267 build_backend = self.get_build_backend()268 if use_wheel:269 base_requirements = ['wheel']270 get_requires = build_backend.get_requires_for_build_wheel271 else:272 base_requirements = []273 get_requires = build_backend.get_requires_for_build_sdist274 # Ensure that the build requirements are properly parsed275 expected = sorted(base_requirements + requirements)276 actual = get_requires()277 assert expected == sorted(actual)278class TestBuildMetaLegacyBackend(TestBuildMetaBackend):279 backend_name = 'setuptools.build_meta:__legacy__'280 # build_meta_legacy-specific tests281 def test_build_sdist_relative_path_import(self, tmpdir_cwd):282 # This must fail in build_meta, but must pass in build_meta_legacy283 build_files(self._relative_path_import_files)284 build_backend = self.get_build_backend()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!