Skip to content

Commit

Permalink
Added testing for only one cog at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
geirawsm committed May 17, 2024
1 parent 5bfa99c commit d9456e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
5 changes: 5 additions & 0 deletions sausage_bot/util/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
action='store_true',
default=False,
dest='not_write_database')
testing_args.add_argument('--single-cog', '-c',
help='Load only one cog for testing purposes',
action='store',
default=False,
dest='single_cog')

maintenance_args = parser.add_argument_group('Maintenance')
maintenance_args.add_argument('--maintenance',
Expand Down
27 changes: 19 additions & 8 deletions sausage_bot/util/cogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from discord.ext import commands

from sausage_bot.util import envs, config
from sausage_bot.util.args import args
from .log import log


Expand Down Expand Up @@ -67,11 +68,21 @@ async def load_and_clean_cogs_internal():
Load cogs from the cog-dir
#autodoc skip#
'''
log.debug(
f'Got these files in `COGS_DIR`: {os.listdir(envs.COGS_DIR)}'
)
for filename in os.listdir(envs.COGS_DIR):
if filename.endswith('.py') and not filename.startswith('_'):
cog_name = filename[:-3]
log.log('Loading cog: {}'.format(cog_name))
await Cogs.load_cog_internal(cog_name)
if args.single_cog:
cog_files = [cog[:-3] for cog in os.listdir(envs.COGS_DIR)]
testing_cog = args.single_cog
if testing_cog in cog_files:
log.log('Loading cog: {}'.format(testing_cog))
await Cogs.load_cog_internal(testing_cog)
log.debug(
f'Loading a single cog for testing purposes: {testing_cog}'
)
else:
log.debug(
f'Got these files in `COGS_DIR`: {os.listdir(envs.COGS_DIR)}'
)
for filename in os.listdir(envs.COGS_DIR):
if filename.endswith('.py') and not filename.startswith('_'):
cog_name = filename[:-3]
log.log('Loading cog: {}'.format(cog_name))
await Cogs.load_cog_internal(cog_name)

0 comments on commit d9456e1

Please sign in to comment.