Best Python code snippet using molecule_python
test_generate_requirements.py
Source: test_generate_requirements.py
1import io2import json3import pytest4from fluidly.pipenv.generate_requirements import generate_requirements5@pytest.fixture6def mock_pipfile_lock():7 def _wrapper(_meta=None, default=None, develop=None):8 pipfile_lock = {9 "_meta": _meta or {},10 "default": default or {},11 "develop": develop or {},12 }13 return io.StringIO(json.dumps(pipfile_lock))14 return _wrapper15def test_generates_pypi_dependency(mock_pipfile_lock):16 pipfile_lock_file = mock_pipfile_lock(17 default={18 "flask": {"version": "==2.0.0"},19 }20 )21 requirements_file = io.StringIO()22 generate_requirements(pipfile_lock_file, requirements_file)23 requirements_file.seek(0)24 assert requirements_file.read() == "flask==2.0.0\n"25def test_generates_git_dependency(mock_pipfile_lock):26 pipfile_lock_file = mock_pipfile_lock(27 default={28 "fluidly-auth": {29 "git": "git@github.com/fluidly/python-shared.git",30 "ref": "d1bfd94894fff06f0580d9c780c99d0d6eb32a46",31 "subdirectory": "fluidly-auth",32 },33 }34 )35 requirements_file = io.StringIO()36 generate_requirements(pipfile_lock_file, requirements_file)37 requirements_file.seek(0)38 assert (39 requirements_file.read()40 == "git+git@github.com/fluidly/python-shared.git@d1bfd94894fff06f0580d9c780c99d0d6eb32a46#subdirectory=fluidly-auth\n"41 )42def test_generates_editable_dependency(mock_pipfile_lock):43 pipfile_lock_file = mock_pipfile_lock(44 default={45 "marshmallow": {46 "editable": True,47 "git": "https://github.com/marshmallow-code/marshmallow.git",48 "ref": "01837167ef1758df1f2decb819e7294200ec9f67",49 },50 }51 )52 requirements_file = io.StringIO()53 generate_requirements(pipfile_lock_file, requirements_file)54 requirements_file.seek(0)55 assert (56 requirements_file.read()57 == "-e git+https://github.com/marshmallow-code/marshmallow.git@01837167ef1758df1f2decb819e7294200ec9f67#egg=marshmallow\n"...
pyutils.py
Source: pyutils.py
1import os2import re3import subprocess4import hashlib5def parse_requirements(requirements_file):6 """7 Parse a requirements.txt file8 :param requirements_file: path to requirements.txt file9 :return: package names10 """11 if os.path.exists(requirements_file):12 with open(requirements_file, 'r') as f:13 deps = list(filter(lambda x: len(x) > 0, map(str.strip, f.read().split('\n'))))14 return [re.split('==|<=|>=|<|>', d)[0] for d in deps]15 return []16def requirements_installed(requirements_file, python_path):17 """18 Checks if the packages in requirements.txt have been installed in the specified19 python path. Note that this does NOT check for versions, just package names20 :param requirements_file: path to requirements.txt21 :param python_path: path to directory where packages are installed22 :return: True if all requirements are installed, false otherwise23 """24 env = os.environ.copy()25 env["PYTHONPATH"] = env.get("PYTHONPATH", "") + ":" + python_path26 reqs = subprocess.check_output(['pip', 'freeze'], env=env)27 installed_packages = [r.decode().split('==')[0] for r in reqs.split()]28 deps = parse_requirements(requirements_file)29 return set(deps) & set(installed_packages) == set(deps)30def compute_file_md5(filename):...
settings.py
Source: settings.py
1from os import getenv, path2from django.conf import settings3from django.core.exceptions import ImproperlyConfigured4REQUIREMENTS_FILE = getattr(5 settings, "PACKAGE_MONITOR_REQUIREMENTS_FILE", None6) or getenv("PACKAGE_MONITOR_REQUIREMENTS_FILE", None)7if REQUIREMENTS_FILE is None:8 raise ImproperlyConfigured("Missing PACKAGE_MONITOR_REQUIREMENTS_FILE setting.")9if not path.exists(REQUIREMENTS_FILE):10 raise ImproperlyConfigured(11 "Invalid REQUIREMENTS_FILE setting: %s" % REQUIREMENTS_FILE12 )13# length of time to cache return data from PyPI...
Check out the latest blogs from LambdaTest on this topic:
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
Most test automation tools just do test execution automation. Without test design involved in the whole test automation process, the test cases remain ad hoc and detect only simple bugs. This solution is just automation without real testing. In addition, test execution automation is very inefficient.
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
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!!