Skip to content

Commit 8107348

Browse files
Add monty stats unit tests
1 parent 6c989bd commit 8107348

File tree

5 files changed

+97
-52
lines changed

5 files changed

+97
-52
lines changed

.coverage

0 Bytes
Binary file not shown.

.travis.yml

-8
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ sudo: required
33
language: python
44
python: 3.8
55

6-
#env:
7-
# global:
8-
# - DOCKER_BUILDKIT=1
9-
# - DOCKER_CLI_EXPERIMENTAL=enabled
10-
116
before_install:
127
- sudo rm -rf /var/lib/apt/lists/*
138
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
@@ -19,9 +14,6 @@ before_install:
1914
- chmod a+x ~/.docker/cli-plugins/docker-buildx
2015

2116
install:
22-
# - docker build --platform=local -o . git://github.com/docker/buildx
23-
# - mkdir -p ~/.docker/cli-plugins
24-
# - mv buildx ~/.docker/cli-plugins/docker-buildx
2517
- pip3 install -r requirements.txt
2618

2719
script:

cov.xml

+44-43
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" ?>
2-
<coverage version="6.3.2" timestamp="1647385319904" lines-valid="1368" lines-covered="272" line-rate="0.1988" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
2+
<coverage version="6.3.2" timestamp="1647896574346" lines-valid="1369" lines-covered="313" line-rate="0.2286" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
33
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
44
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
55
<sources>
66
<source>E:\github\PythonDiscordBot\plugins</source>
77
</sources>
88
<packages>
9-
<package name="." line-rate="0.1988" branch-rate="0" complexity="0">
9+
<package name="." line-rate="0.2286" branch-rate="0" complexity="0">
1010
<classes>
1111
<class name="__init__.py" filename="__init__.py" complexity="0" line-rate="1" branch-rate="0">
1212
<methods/>
@@ -458,49 +458,50 @@
458458
<line number="63" hits="1"/>
459459
</lines>
460460
</class>
461-
<class name="plugin_monty_stats.py" filename="plugin_monty_stats.py" complexity="0" line-rate="0" branch-rate="0">
461+
<class name="plugin_monty_stats.py" filename="plugin_monty_stats.py" complexity="0" line-rate="1" branch-rate="0">
462462
<methods/>
463463
<lines>
464-
<line number="1" hits="0"/>
465-
<line number="2" hits="0"/>
466-
<line number="3" hits="0"/>
467-
<line number="4" hits="0"/>
468-
<line number="5" hits="0"/>
469-
<line number="7" hits="0"/>
470-
<line number="8" hits="0"/>
471-
<line number="10" hits="0"/>
472-
<line number="12" hits="0"/>
473-
<line number="14" hits="0"/>
474-
<line number="16" hits="0"/>
475-
<line number="18" hits="0"/>
476-
<line number="20" hits="0"/>
477-
<line number="22" hits="0"/>
478-
<line number="24" hits="0"/>
479-
<line number="26" hits="0"/>
480-
<line number="28" hits="0"/>
481-
<line number="29" hits="0"/>
482-
<line number="31" hits="0"/>
483-
<line number="32" hits="0"/>
484-
<line number="33" hits="0"/>
485-
<line number="35" hits="0"/>
486-
<line number="37" hits="0"/>
487-
<line number="38" hits="0"/>
488-
<line number="40" hits="0"/>
489-
<line number="41" hits="0"/>
490-
<line number="43" hits="0"/>
491-
<line number="45" hits="0"/>
492-
<line number="47" hits="0"/>
493-
<line number="48" hits="0"/>
494-
<line number="49" hits="0"/>
495-
<line number="50" hits="0"/>
496-
<line number="51" hits="0"/>
497-
<line number="52" hits="0"/>
498-
<line number="55" hits="0"/>
499-
<line number="57" hits="0"/>
500-
<line number="59" hits="0"/>
501-
<line number="61" hits="0"/>
502-
<line number="63" hits="0"/>
503-
<line number="64" hits="0"/>
464+
<line number="1" hits="1"/>
465+
<line number="2" hits="1"/>
466+
<line number="3" hits="1"/>
467+
<line number="4" hits="1"/>
468+
<line number="5" hits="1"/>
469+
<line number="7" hits="1"/>
470+
<line number="8" hits="1"/>
471+
<line number="10" hits="1"/>
472+
<line number="12" hits="1"/>
473+
<line number="14" hits="1"/>
474+
<line number="16" hits="1"/>
475+
<line number="18" hits="1"/>
476+
<line number="20" hits="1"/>
477+
<line number="22" hits="1"/>
478+
<line number="24" hits="1"/>
479+
<line number="26" hits="1"/>
480+
<line number="28" hits="1"/>
481+
<line number="29" hits="1"/>
482+
<line number="31" hits="1"/>
483+
<line number="32" hits="1"/>
484+
<line number="33" hits="1"/>
485+
<line number="35" hits="1"/>
486+
<line number="37" hits="1"/>
487+
<line number="38" hits="1"/>
488+
<line number="40" hits="1"/>
489+
<line number="41" hits="1"/>
490+
<line number="43" hits="1"/>
491+
<line number="45" hits="1"/>
492+
<line number="47" hits="1"/>
493+
<line number="48" hits="1"/>
494+
<line number="49" hits="1"/>
495+
<line number="50" hits="1"/>
496+
<line number="51" hits="1"/>
497+
<line number="52" hits="1"/>
498+
<line number="55" hits="1"/>
499+
<line number="57" hits="1"/>
500+
<line number="59" hits="1"/>
501+
<line number="61" hits="1"/>
502+
<line number="63" hits="1"/>
503+
<line number="64" hits="1"/>
504+
<line number="65" hits="1"/>
504505
</lines>
505506
</class>
506507
<class name="plugin_numusers.py" filename="plugin_numusers.py" complexity="0" line-rate="0" branch-rate="0">

plugins/plugin_monty_stats.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def checkBits(self, bits):
3838
return False
3939

4040
async def runCheer(self, user, amount):
41-
return
41+
return True
4242

4343
async def run(self, message, obj_list):
4444
# Create fresh stat file
@@ -60,5 +60,6 @@ async def run(self, message, obj_list):
6060

6161
await message.channel.send(message.author.mention + ', Monty has been pet ' + str(json_data['pets']) + ' time(s)')
6262

63+
return True
6364
async def stop(self, message):
6465
self.looping = False

tests/test_plugin_monty_stats.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import os
2+
import sys
3+
import unittest
4+
sys.dont_write_bytecode = True
5+
sys.path.append(os.path.abspath('plugins'))
6+
sys.path.append(os.path.abspath('tests'))
7+
8+
from plugin_monty_stats import MontyStats
9+
from injectables.discord_dependencies import *
10+
11+
class TestTemplate(unittest.TestCase):
12+
13+
def test_check_bits(self):
14+
monty = MontyStats()
15+
assert monty.checkBits(0) == False
16+
17+
def test_check_cat_true(self):
18+
monty = MontyStats()
19+
assert monty.checkCat('admin') == True
20+
21+
def test_check_cat_false(self):
22+
monty = MontyStats()
23+
assert monty.checkCat('arrow') == False
24+
25+
class TestAsyncMethods(unittest.IsolatedAsyncioTestCase):
26+
async def test_run_cheer(self):
27+
monty = MontyStats()
28+
assert await monty.runCheer('potato', 0) == True
29+
30+
async def test_run_file_not_exist(self):
31+
a_channel = channel()
32+
a_message = message('!montystats', a_channel)
33+
a_plugin = plugin('!help', 'help menu', '!help')
34+
35+
if os.path.isfile('montystats.json'):
36+
os.remove('montystats.json')
37+
38+
obj_list = [a_plugin]
39+
40+
monty = MontyStats()
41+
assert await monty.run(a_message, obj_list) == True
42+
43+
if os.path.isfile('montystats.json'):
44+
os.remove('montystats.json')
45+
46+
async def test_stop(self):
47+
monty = MontyStats()
48+
await monty.stop('potato')
49+
50+
if __name__ == '__main__':
51+
unittest.main()

0 commit comments

Comments
 (0)