mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
* WIP cog path manager * Initial working state * Get real reloading working * Type error thingy * And fix the tests * Start UI shit * path reordering * Add install path getter/setter and fix config syntax * Determine bot directory at runtime * Add UI commands for install path * Update downloader to use install path * Add sane install path default * Make evaluation of cog install path lazy * Some typing fixes * Add another line to codeowners * Conditionally put install path in paths * Always put install path first * Dont allow people to add the installdir as an additional path, guarantee install dir isn't shown with paths command * Make shit update loaded cogs * Add tests * Another one
58 lines
1.3 KiB
Python
58 lines
1.3 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
from core import cog_manager
|
|
|
|
|
|
@pytest.fixture()
|
|
def cog_mgr(red):
|
|
return red.cog_mgr
|
|
|
|
|
|
@pytest.fixture()
|
|
def default_dir(red):
|
|
return red.main_dir
|
|
|
|
|
|
def test_ensure_cogs_in_paths(cog_mgr, default_dir):
|
|
cogs_dir = default_dir / 'cogs'
|
|
assert cogs_dir in cog_mgr.paths
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_install_path_set(cog_mgr: cog_manager.CogManager, tmpdir):
|
|
path = Path(str(tmpdir))
|
|
await cog_mgr.set_install_path(path)
|
|
assert cog_mgr.install_path == path
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_install_path_set_bad(cog_mgr):
|
|
path = Path('something')
|
|
|
|
with pytest.raises(ValueError):
|
|
await cog_mgr.set_install_path(path)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_add_path(cog_mgr, tmpdir):
|
|
path = Path(str(tmpdir))
|
|
await cog_mgr.add_path(path)
|
|
assert path in cog_mgr.paths
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_add_path_already_install_path(cog_mgr, tmpdir):
|
|
path = Path(str(tmpdir))
|
|
await cog_mgr.set_install_path(path)
|
|
with pytest.raises(ValueError):
|
|
await cog_mgr.add_path(path)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_remove_path(cog_mgr, tmpdir):
|
|
path = Path(str(tmpdir))
|
|
await cog_mgr.add_path(path)
|
|
await cog_mgr.remove_path(path)
|
|
assert path not in cog_mgr.paths
|