Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Commit

Permalink
removed global EXIT_CODE
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephFKnight committed May 27, 2019
1 parent f52713a commit 5bb0c51
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions distest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
from .exceptions import TestRequirementFailure
from .collector import ExpectCalls, TestCollector

# Globals, should all be here
TIMEOUT = 5
# The exit code will be stored here when the program exits, this can be handled in the tester bot
# after run() finished
EXIT_CODE = 0
HELP_TEXT = """\
**::help** - Show this help
**::run** all - Run all tests
Expand All @@ -36,8 +32,6 @@ def __init__(self, target_name: str) -> None:
super().__init__()
self._target_name = target_name.lower()

# s self._setup_done = False

def _find_target(self, server: discord.Guild) -> discord.Member:
for i in server.members:
if self._target_name in i.name.lower():
Expand All @@ -61,14 +55,6 @@ async def run_test(
test.result = TestResult.SUCCESS
return test.result

async def fail_close(self, failure):
global EXIT_CODE
if failure:
EXIT_CODE = 1
else:
EXIT_CODE = 0
await super().close()


class DiscordInteractiveInterface(DiscordBot):
"""
Expand Down Expand Up @@ -183,6 +169,11 @@ def __init__(
self._channel_id = channel_id
self._stats = stats
self._channel = None
self.failure = False

def run(self, token):
super().run(token)
return self.failure

async def _display_stats(self, channel: discord.TextChannel) -> None:
"""
Expand Down Expand Up @@ -255,6 +246,10 @@ def pred(t):
# Status display command
await self._display_stats(self._channel)

async def fail_close(self, failure):
self.failure = failure
await super().close()


def run_dtest_bot(sysargs, test_collector: TestCollector):
from distest.validate_discord_token import token_arg
Expand Down Expand Up @@ -360,5 +355,5 @@ def run_interactive_bot(target_name, token, test_collector):

def run_command_line_bot(target_name, token, run, channel_id, stats, test_collector):
bot = DiscordCliInterface(target_name, test_collector, run, channel_id, stats)
bot.run(token)
exit(EXIT_CODE)
failed = bot.run(token)
exit(1 if failed else 0)

0 comments on commit 5bb0c51

Please sign in to comment.