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

Commit d7e290b

Browse files
committed
Make tests a package
1 parent 1c8c9d2 commit d7e290b

8 files changed

Lines changed: 47 additions & 32 deletions

File tree

disctools/__version_info__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
}
77

88
class last_modified:
9-
day = 19
10-
month = 1
9+
day = 17
10+
month = 2
1111
year = 2021
1212

1313
@classmethod
@@ -61,7 +61,7 @@ def __repr__(self) -> str:
6161
version_info = VersionInfo(
6262
major = 0,
6363
minor = 3,
64-
patch = 1,
64+
patch = 2,
6565
status = status_map["final"],
6666
)
6767

disctools/commands.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,16 @@ def __new__(cls, name, bases, attrs):
6969

7070
class CmdInitType(type):
7171
"""Initializes a Command during definition"""
72-
def __new__(cls, NamE, BaseS, AttrS, **kwargs) -> object: # type: ignore
72+
def __new__(cls, name, bases, attrs, **kwargs) -> object: # type: ignore
7373
meta_args = ()
74-
if '__init_args__' in AttrS:
75-
meta_args = AttrS['__init_args__']
76-
del AttrS['__init_args__']
77-
clas = super().__new__(cls, NamE, BaseS, AttrS)
78-
inst = clas(*meta_args, **kwargs)
79-
return inst
74+
if '__init_args__' in attrs:
75+
meta_args = attrs['__init_args__']
76+
del attrs['__init_args__']
77+
return super().__new__(cls, name, bases, attrs)(*meta_args, **kwargs)
8078

81-
# Metaclass of a metaclass or a function changing
82-
# the super class is extremely complicated hence this.
83-
class CogCmdInitType(CogCommandType):
79+
class CogCmdInitType(CmdInitType, CogCommandType):
8480
"""Initializes a Cog like Cmd during definition"""
85-
def __new__(cls, NamE, BaseS, AttrS, **kwargs) -> object: # type: ignore
86-
meta_args = ()
87-
if '__init_args__' in AttrS:
88-
meta_args = AttrS['__init_args__']
89-
del AttrS['__init_args__']
90-
clas = super().__new__(cls, NamE, BaseS, AttrS)
91-
inst = clas(*meta_args, **kwargs)
92-
return inst
81+
pass
9382

9483

9584
## Commands ##

tests/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from os.path import abspath, dirname
2+
from sys import argv
3+
from sys import path as spath
4+
from test.support import load_package_tests
5+
6+
try:
7+
import disctools
8+
except ModuleNotFoundError:
9+
local = True
10+
else:
11+
local = False
12+
del disctools
13+
14+
def load_tests(loader, *args):
15+
if ("--local" in argv) or local:
16+
spath.insert(0, abspath("."))
17+
print("Testing local disctools package")
18+
19+
return loader.loadTestsFromNames(
20+
["tests.test_bot",
21+
"tests.test_cmd",
22+
"tests.test_context"]
23+
)

tests/__main__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import unittest
1+
"""Disctool tests
22
3-
def test_suite():
4-
return unittest.TestLoader().loadTestsFromNames(["test_bot", "test_cmd", "test_context"])
3+
CLI
4+
---
5+
`--local`, `-l`
6+
Test the local disctools package instead of the installed package
7+
"""
8+
from unittest import main
9+
10+
from . import load_tests
511

612
if __name__ == "__main__":
7-
# Running this file as main tests local code not the installed code
8-
import sys
9-
import os
10-
sys.path.insert(0, os.path.abspath("."))
11-
unittest.main(defaultTest='test_suite')
13+
main()

tests/test_bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from disctools import AutoShardedBot as _AS
44
from disctools import Bot, Command
55

6-
from utils import dummy
6+
from .utils import dummy
77

88

99
class BotTest(unittest.TestCase):

tests/test_cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from disctools import CCmd, Command, ICCmd, ICommand, inject, inject_cmd
44

5-
from utils import dummy as _dummy
5+
from .utils import dummy as _dummy
66

77

88
class CMDTest(unittest.TestCase):

tests/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
"""Utils for tests"""
12

23
async def dummy(*args, **kwargs): pass

version.num

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.1
1+
0.3.2

0 commit comments

Comments
 (0)