Skip to content

Commit

Permalink
Remove explicit passing of event_loop
Browse files Browse the repository at this point in the history
  • Loading branch information
cderici committed Jan 9, 2024
1 parent 2581b0c commit 6c49d56
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 186 deletions.
14 changes: 0 additions & 14 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,6 @@
from juju.client.jujudata import FileJujuData
from juju.controller import Controller

from juju.jasyncio import SingletonEventLoop


@pytest.fixture(scope="session")
def event_loop():
"""
This fixture forces all the asyncio tests
to use the same events loop
"""

loop = SingletonEventLoop().loop
yield loop
loop.close()


def is_bootstrapped():
try:
Expand Down
40 changes: 20 additions & 20 deletions tests/integration/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


@base.bootstrapped
async def test_action(event_loop):
async def test_action():
async with base.CleanModel() as model:
app = await model.deploy('juju-qa-test')
await jasyncio.sleep(10)
Expand All @@ -28,7 +28,7 @@ async def test_action(event_loop):


@base.bootstrapped
async def test_get_set_config(event_loop):
async def test_get_set_config():
async with base.CleanModel() as model:
app = await model.deploy(
'ubuntu',
Expand All @@ -53,7 +53,7 @@ async def test_get_set_config(event_loop):

@base.bootstrapped
@pytest.mark.skip('Update charm')
async def test_status_is_not_unset(event_loop):
async def test_status_is_not_unset():
async with base.CleanModel() as model:
app = await model.deploy(
'ubuntu-0',
Expand All @@ -67,7 +67,7 @@ async def test_status_is_not_unset(event_loop):

@base.bootstrapped
@pytest.mark.skip('Update charm')
async def test_status(event_loop):
async def test_status():
async with base.CleanModel() as model:
app = await model.deploy('ch:juju-qa-test')

Expand All @@ -82,7 +82,7 @@ def app_ready():

@base.bootstrapped
@pytest.mark.skip('Update charm')
async def test_add_units(event_loop):
async def test_add_units():
from juju.unit import Unit

async with base.CleanModel() as model:
Expand All @@ -100,7 +100,7 @@ async def test_add_units(event_loop):


@base.bootstrapped
async def test_deploy_charmhub_charm(event_loop):
async def test_deploy_charmhub_charm():
async with base.CleanModel() as model:
app = await model.deploy('ubuntu')
await model.block_until(lambda: (len(app.units) > 0 and
Expand All @@ -110,7 +110,7 @@ async def test_deploy_charmhub_charm(event_loop):

@base.bootstrapped
@pytest.mark.skip('Skip until a similar k8s solution is found')
async def test_upgrade_charm_switch_channel(event_loop):
async def test_upgrade_charm_switch_channel():
# Note for future:
# This test requires a charm that has different
# revisions for different channels/risks.
Expand Down Expand Up @@ -154,7 +154,7 @@ async def test_upgrade_charm_switch_channel(event_loop):

@base.bootstrapped
@pytest.mark.skip('Update charm')
async def test_upgrade_charm_revision(event_loop):
async def test_upgrade_charm_revision():
async with base.CleanModel() as model:
app = await model.deploy('ubuntu')
await model.block_until(lambda: (len(app.units) > 0 and
Expand All @@ -166,7 +166,7 @@ async def test_upgrade_charm_revision(event_loop):

@base.bootstrapped
@pytest.mark.skip('Update charm')
async def test_upgrade_charm_switch(event_loop):
async def test_upgrade_charm_switch():
async with base.CleanModel() as model:
app = await model.deploy('ubuntu')
await model.block_until(lambda: (len(app.units) > 0 and
Expand All @@ -179,7 +179,7 @@ async def test_upgrade_charm_switch(event_loop):


@base.bootstrapped
async def test_upgrade_local_charm(event_loop):
async def test_upgrade_local_charm():
async with base.CleanModel() as model:
tests_dir = Path(__file__).absolute().parent
charm_path = tests_dir / 'upgrade-charm'
Expand All @@ -192,7 +192,7 @@ async def test_upgrade_local_charm(event_loop):


@base.bootstrapped
async def test_upgrade_local_charm_resource(event_loop):
async def test_upgrade_local_charm_resource():
async with base.CleanModel() as model:
charm_path = INTEGRATION_TEST_DIR / 'file-resource-charm'
resources = {"file-res": "test.file"}
Expand All @@ -212,7 +212,7 @@ async def test_upgrade_local_charm_resource(event_loop):
@base.bootstrapped
@pytest.mark.asyncio
@pytest.mark.skip('Update charm')
async def test_upgrade_charm_resource(event_loop):
async def test_upgrade_charm_resource():
async with base.CleanModel() as model:
app = await model.deploy('cs:~juju-qa/bionic/upgrade-charm-resource-test-0')

Expand All @@ -232,7 +232,7 @@ async def test_upgrade_charm_resource(event_loop):

@base.bootstrapped
@pytest.mark.asyncio
async def test_refresh_with_resource_argument(event_loop):
async def test_refresh_with_resource_argument():
async with base.CleanModel() as model:
app = await model.deploy('juju-qa-test', resources={'foo-file': '2'})
res2 = await app.get_resources()
Expand All @@ -244,7 +244,7 @@ async def test_refresh_with_resource_argument(event_loop):

@base.bootstrapped
@pytest.mark.asyncio
async def test_upgrade_charm_resource_same_rev_no_update(event_loop):
async def test_upgrade_charm_resource_same_rev_no_update():
async with base.CleanModel() as model:
app = await model.deploy('keystone', channel='victoria/stable')
ress = await app.get_resources()
Expand All @@ -255,7 +255,7 @@ async def test_upgrade_charm_resource_same_rev_no_update(event_loop):

@base.bootstrapped
@pytest.mark.asyncio
async def test_refresh_charmhub_to_local(event_loop):
async def test_refresh_charmhub_to_local():
charm_path = INTEGRATION_TEST_DIR / 'charm'
async with base.CleanModel() as model:
app = await model.deploy('ubuntu', application_name='ubu-path')
Expand All @@ -269,7 +269,7 @@ async def test_refresh_charmhub_to_local(event_loop):

@base.bootstrapped
@pytest.mark.asyncio
async def test_local_refresh(event_loop):
async def test_local_refresh():
charm_path = INTEGRATION_TEST_DIR / 'charm'
async with base.CleanModel() as model:
app = await model.deploy('ubuntu')
Expand All @@ -285,7 +285,7 @@ async def test_local_refresh(event_loop):

@base.bootstrapped
@pytest.mark.asyncio
async def test_trusted(event_loop):
async def test_trusted():
async with base.CleanModel() as model:
await model.deploy('ubuntu', trust=True)

Expand All @@ -299,7 +299,7 @@ async def test_trusted(event_loop):


@base.bootstrapped
async def test_app_destroy(event_loop):
async def test_app_destroy():
async with base.CleanModel() as model:
app = await model.deploy('ubuntu')
a_name = app.name # accessing name is impossible after the app is destroyed
Expand All @@ -314,7 +314,7 @@ async def test_app_destroy(event_loop):


@base.bootstrapped
async def test_app_remove_wait_flag(event_loop):
async def test_app_remove_wait_flag():
async with base.CleanModel() as model:
app = await model.deploy('ubuntu')
a_name = app.name
Expand All @@ -325,7 +325,7 @@ async def test_app_remove_wait_flag(event_loop):


@base.bootstrapped
async def test_app_charm_name(event_loop):
async def test_app_charm_name():
async with base.CleanModel() as model:
app = await model.deploy('ubuntu')
await model.wait_for_idle(status="active")
Expand Down
18 changes: 9 additions & 9 deletions tests/integration/test_charmhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@base.bootstrapped
async def test_info(event_loop):
async def test_info():
async with base.CleanModel() as model:
_, name = await model.charmhub.get_charm_id("ubuntu")
assert name == "ubuntu"
Expand All @@ -30,7 +30,7 @@ async def test_info(event_loop):


@base.bootstrapped
async def test_info_with_channel(event_loop):
async def test_info_with_channel():
async with base.CleanModel() as model:
charm_info = await model.charmhub.info("juju-qa-test", "2.0/stable")
assert charm_info['name'] == 'juju-qa-test'
Expand All @@ -48,7 +48,7 @@ async def test_info_with_channel(event_loop):


@base.bootstrapped
async def test_info_not_found(event_loop):
async def test_info_not_found():
async with base.CleanModel() as model:
with pytest.raises(JujuError) as err:
await model.charmhub.info("badnameforapp")
Expand All @@ -57,7 +57,7 @@ async def test_info_not_found(event_loop):

@base.bootstrapped
@pytest.mark.skip('CharmHub facade no longer exists')
async def test_find(event_loop):
async def test_find():
async with base.CleanModel() as model:
result = await model.charmhub.find("kube")

Expand All @@ -69,7 +69,7 @@ async def test_find(event_loop):

@base.bootstrapped
@pytest.mark.skip('CharmHub facade no longer exists')
async def test_find_bundles(event_loop):
async def test_find_bundles():
async with base.CleanModel() as model:
result = await model.charmhub.find("kube", charm_type="bundle")

Expand All @@ -81,7 +81,7 @@ async def test_find_bundles(event_loop):

@base.bootstrapped
@pytest.mark.skip('CharmHub facade no longer exists')
async def test_find_all(event_loop):
async def test_find_all():
async with base.CleanModel() as model:
result = await model.charmhub.find("")

Expand All @@ -93,7 +93,7 @@ async def test_find_all(event_loop):

@base.bootstrapped
@pytest.mark.skip('This tries to test juju controller logic')
async def test_subordinate_charm_zero_units(event_loop):
async def test_subordinate_charm_zero_units():
# normally in pylibjuju deploy num_units defaults to 1, we switch
# that to 0 behind the scenes if we see that the charmhub charm
# we're deploying is a subordinate charm
Expand All @@ -119,14 +119,14 @@ async def test_subordinate_charm_zero_units(event_loop):


@base.bootstrapped
async def test_subordinate_false_field_exists(event_loop):
async def test_subordinate_false_field_exists():
async with base.CleanModel() as model:
assert await model.charmhub.is_subordinate("rsyslog-forwarder-ha")
assert not await model.charmhub.is_subordinate("mysql-innodb-cluster")


@base.bootstrapped
async def test_list_resources(event_loop):
async def test_list_resources():
async with base.CleanModel() as model:
resources = await model.charmhub.list_resources('hello-kubecon')
assert isinstance(resources, list) and len(resources) > 0
2 changes: 1 addition & 1 deletion tests/integration/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@base.bootstrapped
async def test_user_info(event_loop):
async def test_user_info():
async with base.CleanModel() as model:
controller_conn = await model.connection().controller()

Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


@base.bootstrapped
async def test_monitor(event_loop):
async def test_monitor():
async with base.CleanModel() as model:
conn = model.connection()
assert conn.monitor.status == 'connected'
Expand All @@ -35,7 +35,7 @@ async def test_monitor(event_loop):


@base.bootstrapped
async def test_monitor_catches_error(event_loop):
async def test_monitor_catches_error():

async with base.CleanModel() as model:
conn = model.connection()
Expand All @@ -56,7 +56,7 @@ async def test_monitor_catches_error(event_loop):

@base.bootstrapped
@pytest.mark.skip('Update charm')
async def test_full_status(event_loop):
async def test_full_status():
async with base.CleanModel() as model:
await model.deploy(
'ubuntu',
Expand All @@ -71,7 +71,7 @@ async def test_full_status(event_loop):


@base.bootstrapped
async def test_reconnect(event_loop):
async def test_reconnect():
async with base.CleanModel() as model:
kwargs = model.connection().connect_params()
conn = await Connection.connect(**kwargs)
Expand All @@ -87,7 +87,7 @@ async def test_reconnect(event_loop):

@base.bootstrapped
@pytest.mark.skip('tests the websocket protocol, not pylibjuju, needs to be revised')
async def test_redirect(event_loop):
async def test_redirect():
controller = Controller()
await controller.connect()
kwargs = controller.connection().connect_params()
Expand Down Expand Up @@ -233,7 +233,7 @@ def _find_free_port(self):


@base.bootstrapped
async def test_verify_controller_cert(event_loop):
async def test_verify_controller_cert():
jujudata = FileJujuData()
controller_name = jujudata.current_controller()
endpoint = jujudata.controllers()[controller_name]['api-endpoints'][0]
Expand Down
Loading

0 comments on commit 6c49d56

Please sign in to comment.