How to use test_container method in avocado

Best Python code snippet using avocado_python

test_container.py

Source:test_container.py Github

copy

Full Screen

1import pytest2from src import container3@pytest.fixture(autouse=True) 4def test_container():5 return container.Container()6class TestInitialization:7 def test_input(self, test_container):8 assert test_container.inputs['A'] == {'inner_component': None, 'outer_component': None, 'signal': None}9 10 def test_output(self, test_container):11 assert test_container.outputs['Z'] == {'inner_component': None, 'outer_component': None, 'signal': None}12 13 def test_inits_with_input_count(self, test_container):14 assert test_container.input_count == 115 16 def test_inits_with_output_count(self, test_container):17 assert test_container.output_count == 118 ...

Full Screen

Full Screen

listbox.py

Source:listbox.py Github

copy

Full Screen

1import gooeypie as gp2from random import randint3NUM_RANDOM_ITEMS = 154app = gp.GooeyPieApp('New Listbox Tests')5def display_items(event):6 """Test for items getter"""7 items = listbox.items8 output.prepend(f'{len(items)} items: {items}\n')9def add_items(event):10 """Testing for items setter"""11 random_numbers = [randint(1, 100) for _ in range(NUM_RANDOM_ITEMS)]12 random_numbers = [n + 1 for n in range(NUM_RANDOM_ITEMS)]13 listbox.items = random_numbers14 output.prepend(f'Set listbox to {NUM_RANDOM_ITEMS} random numbers\n')15def add_item(event):16 """Testing for add_item """17 listbox.add_item(add_what.text)18 output.prepend(f'Added {add_what.text} to end\n')19def add_item_to_start(event):20 """Testing for add_item """21 listbox.add_item_to_start(add_start_what.text)22 output.prepend(f'Added {add_start_what.text} to start\n')23def add_item_to_index(event):24 """Testing for add_item_at"""25 item = str(randint(50, 100))26 listbox.add_item_at(int(add_where_index.text), item)27 output.prepend(f'Added {item} to index {int(add_where_index.text)}\n')28def remove_item(event):29 """Testing for remove_item"""30 output.prepend(f'Removed {listbox.remove_item(int(remove_where.text))}\n')31def set_multiple(event):32 """Change the listbox to allow multiple selection"""33 listbox.multiple_selection = multiple.checked34 output.prepend(f'Set multiple selection to {multiple.checked}\n')35def get_selected(event):36 output.prepend(f'Selected item(s): {listbox.selected}\n')37def get_selected_index(event):38 output.prepend(f'Selected index: {listbox.selected_index}\n')39def remove_selected(event):40 output.prepend(f'Removed item(s): {listbox.remove_selected()}\n')41def select_at(event):42 if ',' in select_where.text:43 # Multiple indexes specified44 indexes = [int(index.strip()) for index in select_where.text.split(',')]45 for index in indexes:46 listbox.selected_index = index47 else:48 # Single index specified49 listbox.selected_index = int(select_where.text)50 output.prepend(f'Selected item at index(es) {select_where.text}\n')51def select(event):52 if event.widget == select_all:53 listbox.select_all()54 if event.widget == select_none:55 listbox.select_none()56def set_scrollbar(event):57 """Changes the visibility setting of the scrollbar"""58 listbox.scrollbar = scrollbar_option.selected59 output.prepend(f'Changed scrollbar to {scrollbar_option.selected}\n')60def select_event(event):61 output.prepend(f"'{listbox.selected}' selected on listbox\n")62def enable_disable_listboxes(event):63 listbox.disabled = not listbox.disabled64 state = 'Disabled' if listbox.disabled else 'Enabled'65 output.prepend(f'{state} listbox\n')66def set_selected(event):67 listbox.selected = randint(100, 200)68def clear(event):69 listbox.clear()70def event_test(event):71 output.prepend_line(f'Select event triggered item(s): {listbox.selected}')72# Listbox Container73listbox_container = gp.LabelContainer(app, 'New Listbox')74listbox = gp.Listbox(listbox_container)75listbox.width = 20076multiple = gp.Checkbox(listbox_container, 'Allow multiple selection')77multiple.add_event_listener('change', set_multiple)78scrollbar_option = gp.Dropdown(listbox_container, ['auto', 'visible', 'hidden'])79scrollbar_option.add_event_listener('select', set_scrollbar)80listbox_container.set_grid(3, 1)81listbox_container.set_row_weights(1, 0, 0)82listbox_container.add(listbox, 1, 1, fill=True, stretch=True)83listbox_container.add(multiple, 2, 1)84listbox_container.add(scrollbar_option, 3, 1)85listbox.add_event_listener('select', event_test)86# Testing operations Container87test_container = gp.LabelContainer(app, 'Tests')88setter_button = gp.Button(test_container, 'Set some random values', add_items)89items_button = gp.Button(test_container, 'Get Items', display_items)90add_button = gp.Button(test_container, 'Add Item', add_item)91add_what = gp.Input(test_container)92add_start_button = gp.Button(test_container, 'Add Item to start', add_item_to_start)93add_start_what = gp.Input(test_container)94add_where_button = gp.Button(test_container, 'Add random item to index', add_item_to_index)95add_where_index = gp.Input(test_container)96remove_button = gp.Button(test_container, 'Delete item at index', remove_item)97remove_where = gp.Input(test_container)98selected_button = gp.Button(test_container, 'Get selected value(s)', get_selected)99selected_index_button = gp.Button(test_container, 'Get selected index(es)', get_selected_index)100select_button = gp.Button(test_container, 'Select at index(es)', select_at)101select_where = gp.Input(test_container)102select_all = gp.Button(test_container, 'Select all', select)103select_none = gp.Button(test_container, 'Select none', select)104remove_selection = gp.Button(test_container, 'Remove selected', remove_selected)105disable = gp.Button(test_container, 'Enable/disable listboxes', enable_disable_listboxes)106set_select = gp.Button(test_container, 'Set selected to random', set_selected)107clear = gp.Button(test_container, 'Clear all', clear)108test_container.set_grid(10, 2)109test_container.set_column_weights(1, 1)110test_container.add(setter_button, 1, 1, fill=True)111test_container.add(items_button, 1, 2, fill=True)112test_container.add(add_button, 2, 1, fill=True)113test_container.add(add_what, 2, 2, valign="middle", fill=True)114test_container.add(add_start_button, 3, 1, fill=True)115test_container.add(add_start_what, 3, 2, valign="middle", fill=True)116test_container.add(add_where_button, 4, 1, fill=True)117test_container.add(add_where_index, 4, 2, valign="middle", fill=True)118test_container.add(remove_button, 5, 1, fill=True)119test_container.add(remove_where, 5, 2, valign="middle", fill=True)120test_container.add(selected_button, 6, 1, fill=True)121test_container.add(selected_index_button, 6, 2, fill=True)122test_container.add(select_button, 7, 1, fill=True)123test_container.add(select_where, 7, 2, fill=True)124test_container.add(select_all, 8, 1, fill=True)125test_container.add(select_none, 8, 2, fill=True)126test_container.add(remove_selection, 9, 1, fill=True)127test_container.add(disable, 9, 2, fill=True)128test_container.add(set_select, 10, 1, fill=True)129test_container.add(clear, 10, 2, fill=True)130# Output container131output_container = gp.LabelContainer(app, 'Output')132output = gp.Textbox(output_container)133output.height = 10134output_container.set_grid(1, 1)135output_container.add(output, 1, 1, fill=True, stretch=True)136# Add containers to main window and run137app.set_grid(2, 2)138app.set_column_weights(1, 0)139app.set_row_weights(1, 0)140app.add(listbox_container, 1, 1, stretch=True, fill=True)141app.add(test_container, 1, 2, fill=True)142app.add(output_container, 2, 1, column_span=2, fill=True, stretch=True)...

Full Screen

Full Screen

test_secrets.py

Source:test_secrets.py Github

copy

Full Screen

1import pytest2from jobsworth import config3from jobsworth.util import secrets, databricks, error4from tests.shared import *5def test_reads_secret_from_scope(test_container):6 provider = secrets.Secrets(session=test_container.session,7 config=job_config(),8 secrets_provider=dbutils_wrapper()).clear_cache()9 the_secret = provider.get_secret("my_secret")10 assert the_secret.is_right()11 assert the_secret.value == "from: my_domain.my_service.test/my_secret generates a-secret"12def test_caches_secret(test_container):13 provider = secrets.Secrets(session=test_container.session,14 config=job_config(),15 secrets_provider=dbutils_wrapper()).clear_cache()16 provider.get_secret("my_secret")17 assert provider.secrets_cache == {'my_secret': 'from: my_domain.my_service.test/my_secret generates a-secret'}18def test_with_loaded_secrets(test_container):19 test_secrets = {"my_domain.my_service.test":20 {'my_secret': 'a-secret'}21 }22 provider = secrets.Secrets(23 session=test_container.session,24 config=job_config(),25 secrets_provider=dbutils_wrapper(test_secrets)).clear_cache()26 the_secret = provider.get_secret("my_secret")27 assert the_secret.value == "a-secret"28def test_secret_not_available(test_container):29 test_secrets = {"my_domain.my_service.test":30 {'my_secret': 'a-secret'}31 }32 provider = secrets.Secrets(session=test_container.session,33 config=job_config(),34 secrets_provider=dbutils_wrapper(test_secrets)).clear_cache()35 the_secret = provider.get_secret("not_a_secret_key")36 assert the_secret.is_left()37 assert isinstance(the_secret.error(), error.SecretError)38 assert the_secret.error().message == "Secret does not exist with scope: my_domain.my_service.test and key: not_a_secret_key"39def test_override_scope(test_container):40 test_secrets = {"overridden_scope":41 {'my_secret': 'a-secret'}42 }43 provider = secrets.Secrets(session=test_container.session,44 config=job_config(),45 secrets_provider=dbutils_wrapper(test_secrets),46 scope_override="overridden_scope").clear_cache()47 the_secret = provider.get_secret("my_secret")48 assert the_secret.value == "a-secret"49def test_invalid_provider(test_container):50 result = secrets.Secrets(session=test_container.session,51 config=job_config(),52 secrets_provider=databricks.DatabricksUtilMockWrapper).get_secret(53 "blah")54 assert result.is_left()55def test_session_initialised(test_container):56 from pyspark.sql import session57 from tests.shared import dependencies as deps58 the_secret = deps.secrets_provider().get_secret("CosmosDBAuthorizationKey")59 assert the_secret.value == "a-secret"60 assert isinstance(deps.secrets_provider().secret_provider.utils().session, session.SparkSession)61#62# Helpers63#64def job_config():65 return config.JobConfig(data_product_name="my_data_product_name",66 domain_name="my_domain",67 service_name="my_service").configure_hive_db(db_name="my_db",68 db_file_system_path_root="spark-warehouse",...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful