Best Python code snippet using prospector_python
test_loader.py
Source:test_loader.py
...43 loader._get_yaml('foo.yml')44 e = exc.value45 assert str(e).startswith("Error parsing 'foo.yml': ")46 assert str(e).endswith('line 1, column 1')47def test_load_content(mocker):48 bp = Blueprint()49 load_vars = mocker.patch('populous.loader._load_vars')50 load_items = mocker.patch('populous.loader._load_items')51 # empty content52 loader._load_content(bp, None)53 loader._load_content(bp, {})54 loader._load_content(bp, [])55 assert load_vars.called is False56 assert load_items.called is False57 # wrong type58 with pytest.raises(ValidationError) as e:59 loader._load_content(bp, ['foo'])60 assert "Got a 'list'" in str(e.value)61 # unknown keys62 with pytest.raises(ValidationError) as e:63 loader._load_content(bp, {'foo': None})64 assert "Unknown key(s) in blueprint: 'foo'" in str(e.value)65 with pytest.raises(ValidationError) as e:66 loader._load_content(bp, {'items': None, 'foo': None, 'bar': None})67 assert "Unknown key(s) in blueprint: 'bar, foo'" in str(e.value)68 # valid content69 mocker.resetall()70 loader._load_content(bp, {'items': [{'foo': 42}]})71 assert load_vars.call_args == mocker.call(bp, {})72 assert load_items.call_args == mocker.call(bp, [{'foo': 42}])73 mocker.resetall()74 loader._load_content(bp, {'vars': {'foo': 'bar'}})75 assert load_vars.call_args == mocker.call(bp, {'foo': 'bar'})76 assert load_items.call_args == mocker.call(bp, [])77 mocker.resetall()78 loader._load_content(79 bp, {'vars': {'foo': 'bar'}, 'items': [{'bar': 'foo'}]}80 )81 assert load_vars.call_args == mocker.call(bp, {'foo': 'bar'})82 assert load_items.call_args == mocker.call(bp, [{'bar': 'foo'}])83def test_load_vars(mocker):84 bp = Blueprint()85 add_var = mocker.patch.object(bp, 'add_var')86 # wrong type87 with pytest.raises(ValidationError) as e:88 loader._load_vars(bp, ['foo'])89 assert "must be a dict, not a list." in str(e.value)90 # empty value91 loader._load_vars(bp, {})92 assert add_var.called is False...
website.py
Source:website.py
...43 values["version"] = flask.current_app.config["WEBSITE_VERSION"]44 return flask.url_for(endpoint, **values)45def home():46 view_data = {47 "identity": _load_content("static/identity/identity.yaml"),48 "contact": _load_content("static/contact/contact.yaml"),49 "introduction": _load_content("static/introduction/introduction.yaml"),50 }51 return flask.render_template("home.html", title = "Home", **view_data)52def education():53 view_data = {54 "education": _load_content("static/education/education.yaml", []),55 }56 return flask.render_template("education.html", title = "Education", **view_data, encoding = "utf-8")57def skills():58 view_data = {59 "skill": _load_content("static/skill/skill.yaml", []),60 }61 return flask.render_template("skills.html", title = "Skills", **view_data)62def projects():63 view_data = {64 "project": _load_content("static/project/project.yaml", []),65 }66 return flask.render_template("projects.html", title = "Projects", **view_data)67def work_experience():68 view_data = {69 "work_experience": _load_content("static/work_experience/work_experience.yaml", []),70 }71 return flask.render_template("work_experience.html", title = "Work Experience", **view_data)72def _get_error_message(status_code): # pylint: disable = too-many-return-statements73 if status_code == 400:74 return "Bad request"75 if status_code == 401:76 return "Unauthorized"77 if status_code == 403:78 return "Forbidden"79 if status_code == 404:80 return "Page not found"81 if status_code == 405:82 return "Method not allowed"83 if status_code == 500:84 return "Internal server error"85 if 400 <= status_code < 500:86 return "Client error"87 if 500 <= status_code < 600:88 return "Server error"89 return "Unknown error"90def _load_content(file_path, default_value = None):91 file_path = os.path.join(flask.current_app.root_path, file_path)92 if not os.path.exists(file_path):93 return default_value94 with open(file_path, mode = "r", encoding = "utf-8") as content_file:95 if file_path.endswith(".json"):96 content = json.load(content_file)97 elif file_path.endswith(".yaml"):98 content = yaml.safe_load(content_file)99 else:100 content = content_file.read()101 if content is None or content == "":102 return default_value...
importer.py
Source:importer.py
...22 with get_session() as session:23 # Load the content from the regular files24 game_contents = GameContents()25 for group in FileGroup:26 decks = _load_content(27 Deck,28 content_dir,29 group,30 FileCategory.DECKS,31 game_contents32 )33 elements = _load_content(34 Element,35 content_dir,36 group,37 FileCategory.ELEMENTS,38 game_contents39 )40 endings = _load_content(41 Ending,42 content_dir,43 group,44 FileCategory.ENDINGS,45 game_contents46 )47 legacies = _load_content(48 Legacy,49 content_dir,50 group,51 FileCategory.LEGACIES,52 game_contents53 )54 recipes = _load_content(55 Recipe,56 content_dir,57 group,58 FileCategory.RECIPES,59 game_contents60 )61 verbs = _load_content(62 Verb,63 content_dir,64 group,65 FileCategory.VERBS,66 game_contents67 )68 # Create the dynamically generated secondary tables69 Base.metadata.create_all()70 session.add_all(decks)71 session.add_all(elements)72 session.add_all(endings)73 session.add_all(legacies)74 session.add_all(recipes)75 session.add_all(verbs)76def _load_content(77 content_class: Type[GameContentMixin],78 content_dir: Path,79 group: FileGroup,80 category: FileCategory,81 game_contents: GameContents82) -> List[GameContentMixin]:83 content = []84 for file_name, file_data in _load_json_data(85 content_dir/group.value/category.value86 ):87 file = File(category, group, str(file_name))88 translations = {}89 for culture in ADDITIONAL_CULTURES:90 localised_path = content_dir/f'{group.value}_{culture}'/category.value/str(file_name)...
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!!