Best Python code snippet using lisa_python
addon.py
Source: addon.py
1#!/usr/bin/env python2from xbmcswift import xbmc, xbmcgui, Plugin3from resources.lib.mubi import Mubi4PLUGIN_NAME = 'MUBI'5PLUGIN_ID = 'plugin.video.mubi'6plugin = Plugin(PLUGIN_NAME, PLUGIN_ID, __file__)7if not plugin.get_setting("username"):8 plugin.open_settings()9mubi_session = Mubi()10mubi_session.login(plugin.get_setting("username"),11 plugin.get_setting("password"))12@plugin.route('/')13def index():14 items = [{'label': plugin.get_string(31001), 'is_folder': True,15 'url': plugin.url_for('select_filter')},16 {'label': plugin.get_string(31002), 'is_folder': True,17 'url': plugin.url_for('show_cinemas')},18 {'label': plugin.get_string(31003), 'is_folder': True,19 'url': plugin.url_for('show_films', filter='watchlist',20 argument='0', page='1')},21 {'label': plugin.get_string(31004), 'is_folder': True,22 'url': plugin.url_for('show_search_targets')}]23 return plugin.add_items(items)24@plugin.route('/films')25def select_filter():26 options = [{'label': plugin.get_string(31005), 'is_folder': True,27 'url': plugin.url_for('show_films', filter='all',28 argument='0', page='1')},29 {'label': plugin.get_string(31006), 'is_folder': True,30 'url': plugin.url_for('show_genres')},31 {'label': plugin.get_string(31007), 'is_folder': True,32 'url': plugin.url_for('show_countries')},33 {'label': plugin.get_string(31008), 'is_folder': True,34 'url': plugin.url_for('show_languages')}]35 return plugin.add_items(options)36@plugin.route('/cinemas')37def show_cinemas():38 cinemas = mubi_session.get_all_programs()39 items = [{'label': x.title, 'is_folder': True, 'thumbnail': x.picture,40 'url': plugin.url_for('show_cinema_films', cinema=x.identifier)}41 for x in cinemas]42 return plugin.add_items(items)43@plugin.route('/cinemas/<cinema>')44def show_cinema_films(cinema):45 films = mubi_session.get_program_films(cinema)46 items = [{'label': x[0], 'is_folder': False, 'is_playable': True,47 'thumbnail': x[2],48 'url': plugin.url_for('play_film', identifier=x[1])}49 for x in films]50 return plugin.add_items(items)51@plugin.route('/search')52def show_search_targets():53 targets = [{'label': plugin.get_string(31009), 'is_folder': True,54 'url': plugin.url_for('show_search', target='film')},55 {'label': plugin.get_string(31010), 'is_folder': True,56 'url': plugin.url_for('show_search', target='person')}]57 return plugin.add_items(targets)58@plugin.route('/search/<target>')59def show_search(target=None):60 if target == 'film':61 label = plugin.get_string(31013)62 else:63 label = plugin.get_string(31014)64 keyboard = xbmc.Keyboard('', label)65 keyboard.doModal()66 if keyboard.isConfirmed() and keyboard.getText():67 search_string = keyboard.getText()68 url = plugin.url_for('show_search_results', target=target,69 term=search_string)70 plugin.redirect(url)71@plugin.route('/search/<target>/<term>')72def show_search_results(target, term):73 if target == 'film':74 results = mubi_session.search_film(term)75 items = [{'label': x[0], 'is_folder': False, 'is_playable': True,76 'url': plugin.url_for('play_film', identifier=unicode(x[1])),77 'thumbnail': x[2]} for x in results]78 return plugin.add_items(items)79 elif target == 'person':80 results = mubi_session.search_person(term)81 items = [{'label': x[0], 'is_folder': True,82 'url': plugin.url_for('show_person_films',83 person=unicode(x[1])),84 'thumbnail': x[2]}85 for x in results]86 return plugin.add_items(items)87@plugin.route('/persons/<person>')88def show_person_films(person):89 films = mubi_session.get_person_films(person)90 items = [{'label': x[0], 'is_folder': False, 'is_playable': True,91 'url': plugin.url_for('play_film', identifier=x[1]),92 'thumbnail': x[2]} for x in films]93 return plugin.add_items(items)94@plugin.route('/films/<filter>/<argument>/<page>')95def show_films(filter, argument, page):96 page = int(page)97 if filter == 'all':98 num_pages, films = mubi_session.get_all_films(page=page)99 elif filter == 'watchlist':100 films = mubi_session.get_watchlist()101 num_pages = 1102 elif filter == 'genre':103 num_pages, films = mubi_session.get_all_films(genre=argument,104 page=page)105 elif filter == 'country':106 num_pages, films = mubi_session.get_all_films(country=argument,107 page=page)108 elif filter == 'language':109 num_pages, films = mubi_session.get_all_films(language=argument,110 page=page)111 items = [{'label': x[0], 'is_folder': False, 'is_playable': True,112 'url': plugin.url_for('play_film', identifier=x[1]),113 'thumbnail': x[2]}114 for x in films]115 if len(items) == 0:116 xbmcgui.Dialog().ok(plugin.get_string(30000), plugin.get_string(31015))117 plugin.redirect(plugin.url_for('select_filter'))118 if page > 1:119 items.append({'label': plugin.get_string(31011), 'is_folder': True,120 'url': plugin.url_for('show_films', filter=filter,121 argument=argument,122 page=unicode(page - 1))})123 if (num_pages - page) > 0:124 items.append({'label': plugin.get_string(31012), 'is_folder': True,125 'url': plugin.url_for('show_films', filter=filter,126 argument=argument,127 page=unicode(page + 1))})128 return plugin.add_items(items)129@plugin.route('/play/<identifier>')130def play_film(identifier):131 return plugin.set_resolved_url(mubi_session.get_play_url(identifier))132@plugin.route('/list/genres')133def show_genres():134 items = [{'label': x, 'is_folder': True,135 'url': plugin.url_for('show_films', filter='genre',136 argument=unicode(mubi_session.genres[x]),137 page='1')}138 for x in sorted(mubi_session._CATEGORIES)]139 return plugin.add_items(items)140@plugin.route('/list/countries')141def show_countries():142 items = [{'label': x, 'is_folder': True,143 'url': plugin.url_for('show_films', filter='country',144 argument=unicode(mubi_session145 .countries[x]),146 page='1')}147 for x in sorted(mubi_session.countries)]148 return plugin.add_items(items)149@plugin.route('/list/languages')150def show_languages():151 items = [{'label': x, 'is_folder': True,152 'url': plugin.url_for('show_films', filter='language',153 argument=unicode(mubi_session154 .languages[x]),155 page='1')}156 for x in sorted(mubi_session._LANGUAGES)]157 return plugin.add_items(items)158if __name__ == '__main__':...
tests.py
Source: tests.py
1import commands2import unittest3from unittest import mock4from click.testing import CliRunner5class TestIgnoreCommand(unittest.TestCase):6 @mock.patch("commands.os")7 def test_repo_without_gitignore(self, os_mock):8 os_mock.path.exists.return_value = False9 gitignore_files = commands.get_gitignore_files("git path")10 self.assertEqual(len(gitignore_files), 0)11 self.assertIsInstance(gitignore_files, list)12 @mock.patch("commands.os")13 @mock.patch("builtins.open", new_callable = mock.mock_open, read_data="\na1\n \n\na2\na3\n")14 def test_repo_with_gitignore(self, open_mock, os_mock):15 os_mock.path.exists.return_value = True16 gitignore_files = commands.get_gitignore_files("git path")17 self.assertEqual(len(gitignore_files), 3)18 @mock.patch("commands.os")19 def test_get_dir_files(self, os_mock):20 files = ["archivo1", "archivo2", "archivo3"]21 output = {k:{"file_name": f"inside path/{k}", "is_folder": False} for k in files}22 os_mock.listdir.return_value = files23 os_mock.path.isdir.return_value = False24 dir_files = commands.get_files("git path/inside path", "git path")25 self.assertDictEqual(dir_files, output)26 @mock.patch("commands.os")27 def test_get_dir_folders(self, os_mock):28 files = ["folder1", "folder2", "folder3"]29 output = {f"{k}/":{"file_name": f"inside path/{k}/", "is_folder": True} for k in files}30 os_mock.listdir.return_value = files31 os_mock.path.isdir.return_value = True32 dir_files = commands.get_files("git path/inside path", "git path")33 self.assertDictEqual(dir_files, output)34 @mock.patch("commands.os")35 def test_get_dir_files_top(self, os_mock):36 files = ["archivo1", "archivo2", "archivo3"]37 output = {k:{"file_name": k, "is_folder": False} for k in files}38 os_mock.listdir.return_value = files39 os_mock.path.isdir.return_value = False40 dir_files = commands.get_files("git path", "git path")41 self.assertDictEqual(dir_files, output)42 def test_choices(self):43 dir_files = {44 "a1":{45 "file_name": "inside path/a1",46 "is_folder": False47 },48 "a2":{49 "file_name": "inside path/a2",50 "is_folder": False51 },52 "a3":{53 "file_name": "inside path/a3",54 "is_folder": False55 },56 "f1/":{57 "file_name": "inside path/f1/",58 "is_folder": True59 },60 "f2/":{61 "file_name": "inside path/f2/",62 "is_folder": True63 },64 "f3/":{65 "file_name": "inside path/f3/",66 "is_folder": True67 }68 }69 gitignore_files = ["a1", "inside path/a2","inside path/inside/f1/", "inside path/f2/"]70 expected_output = [71 {"name": "a1"},72 {"name": "a2", "checked": True},73 {"name": "a3"},74 {"name": "f1/"},75 {"name": "f2/", "checked": True},76 {"name": "f3/"},77 ]78 choices = commands.create_choices(dir_files, gitignore_files)79 self.assertListEqual(choices, expected_output)80 for key in ["a2", "f2/"]:81 self.assertTrue(dir_files[key]["is_ignored"])82 for key in ["a1", "f1/", "a3", "f3/"]:83 self.assertFalse(dir_files[key]["is_ignored"])84 85 @mock.patch("builtins.open")86 def test_update_gitignore_add_files(self, open_mock):87 dir_files = {88 "a1":{89 "file_name": "inside path/a1",90 "is_folder": False,91 "is_ignored": False92 },93 "a2":{94 "file_name": "inside path/a2",95 "is_folder": False,96 "is_ignored": True97 },98 "a3":{99 "file_name": "inside path/a3",100 "is_folder": False,101 "is_ignored": False102 },103 "f1/":{104 "file_name": "inside path/f1/",105 "is_folder": True,106 "is_ignored": False107 },108 "f2/":{109 "file_name": "inside path/f2/",110 "is_folder": True,111 "is_ignored": True112 },113 "f3/":{114 "file_name": "inside path/f3/",115 "is_folder": True,116 "is_ignored": False117 }118 }119 gitignore_files = ["a1", "inside path/a2","inside path/inside/f1/", "inside path/f2/"]120 answers = ["a1", "a2", "f2/", "f3/"]121 ignored_files = gitignore_files + ["a1", "f3/"]122 ignored_files = "\n".join(ignored_files)123 open_mock = mock.mock_open()124 new_files = commands.update_gitignore(answers, dir_files, gitignore_files, "git path")125 126 self.assertListEqual(new_files, ["a1", "f3/"])127 open_mock.assert_called_once_with('git path/.gitignore', 'w')128 handle = open_mock()129 handle.write.assert_called_once_with(ignored_files)130 131if __name__ == '__main__':...
object_exist.py
Source: object_exist.py
...75 raise ValueError("Invalid value for `exists`, must not be `None`") # noqa: E50176 self._exists = exists77 78 @property79 def is_folder(self):80 """81 Gets the is_folder. # noqa: E50182 True if it is a folder, false if it is a file. # noqa: E50183 :return: The is_folder. # noqa: E50184 :rtype: bool85 """86 return self._is_folder87 @is_folder.setter88 def is_folder(self, is_folder):89 """90 Sets the is_folder.91 True if it is a folder, false if it is a file. # noqa: E50192 :param is_folder: The is_folder. # noqa: E50193 :type: bool94 """95 if is_folder is None:96 raise ValueError("Invalid value for `is_folder`, must not be `None`") # noqa: E50197 self._is_folder = is_folder98 def to_dict(self):99 """Returns the model properties as a dict"""100 result = {}101 for attr, _ in six.iteritems(self.swagger_types):102 value = getattr(self, attr)...
Check out the latest blogs from LambdaTest on this topic:
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.
It’s strange to hear someone declare, “This can’t be tested.” In reply, I contend that everything can be tested. However, one must be pleased with the outcome of testing, which might include failure, financial loss, or personal injury. Could anything be tested when a claim is made with this understanding?
When it comes to UI components, there are two versatile methods that we can use to build it for your website: either we can use prebuilt components from a well-known library or framework, or we can develop our UI components from scratch.
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!!