packaging and testing

This commit is contained in:
Nikolaj Danger
2020-03-24 15:30:45 +01:00
parent de6ee115e7
commit 5394046aeb
10 changed files with 145 additions and 72 deletions

View File

@ -1 +1,7 @@
from .gwendolynFuncs import helloFunc, roll_dice, cap, imageFunc, movieFunc, parseChar, parseRoll, spellFunc, monsterFunc, nameGen, tavernGen from .gwendolynFuncs import helloFunc, roll_dice, cap, imageFunc
from .swfuncs import parseChar, parseRoll
from .lookup import spellFunc, monsterFunc
from .other import nameGen, tavernGen, movieFunc

View File

@ -11,7 +11,7 @@ from .lookup import lookupFuncs
from .other import movie, generators from .other import movie, generators
from .swfuncs import swchar, swroll from .swfuncs import swchar, swroll
def roll_dice(author, rollStr: str = "1d20"): def roll_dice(author : str, rollStr : str = "1d20"):
print("Rolling "+str(rollStr)) print("Rolling "+str(rollStr))
if rollStr == '0/0': # easter eggs if rollStr == '0/0': # easter eggs
return("What do you expect me to do, destroy the universe?") return("What do you expect me to do, destroy the universe?")
@ -19,7 +19,7 @@ def roll_dice(author, rollStr: str = "1d20"):
adv = 0 adv = 0
if re.search('(^|\s+)(adv|dis)(\s+|$)', rollStr) is not None: if re.search('(^|\s+)(adv|dis)(\s+|$)', rollStr) is not None:
adv = 1 if re.search('(^|\s+)adv(\s+|$)', rollStr) is not None else -1 adv = 1 if re.search('(^|\s+)adv(\s+|$)', rollStr) is not None else -1
rollStr = re.sub('(adv|dis)(\s+|$)', '', rollStr) rollStr = re.sub('(adv|dis)(\s+|$)', '', rollSt
res = dice.roll(rollStr, adv=adv) res = dice.roll(rollStr, adv=adv)
out = res.result out = res.result
outStr = author + ' :game_die:\n' + out outStr = author + ' :game_die:\n' + out
@ -100,50 +100,3 @@ def imageFunc():
print("Successfully returned an image") print("Successfully returned an image")
print("") print("")
return(image) return(image)
def movieFunc():
try:
print("Creating IMDb object")
ia = imdb.IMDb()
print("Picking a movie")
movs = open("funcs/other/movies.txt", "r")
movlist = movs.read().split("\n")
mov = random.choice(movlist)
movs.close()
print("Searching for "+mov)
s_result = ia.search_movie(mov)
print("Getting the data")
movie = s_result[0]
ia.update(movie)
cast = movie['cast']
pcast = ""
for x in range(3):
if cast[x]:
pcast += cast[x]['name']+", "
print("Successfully ran !movie")
print("")
return(movie['title'], movie['plot'][0].split("::")[0], movie['cover url'].replace("150","600").replace("101","404"), pcast[:-2])
except:
print("Something bad happened...")
return("error","","","")
def parseChar(user : str, cmd : str = ""):
return swchar.parseChar(user,cmd)
def parseRoll(user : str, cmd : str = ""):
return swroll.parseRoll(user,cmd)
def spellFunc(content):
return lookupFuncs.spellFunc(content)
def monsterFunc(content):
return lookupFuncs.monsterFunc(content)
def nameGen():
return generators.nameGen()
def tavernGen():
return generators.tavernGen()

1
funcs/lookup/__init__.py Normal file
View File

@ -0,0 +1 @@
from .lookupFuncs import spellFunc, monsterFunc

2
funcs/other/__init__.py Normal file
View File

@ -0,0 +1,2 @@
from .generators import nameGen, tavernGen
from .movie import movieFunc

View File

@ -36,7 +36,7 @@ def nameGen():
if new_letter == "\n": if new_letter == "\n":
done = True done = True
genName = "".join(chain) genName = "".join(chain)
print("Generated "+genName+"\n") print("Generated "+genName)
return(genName) return(genName)
def tavernGen(): def tavernGen():

View File

@ -2,20 +2,20 @@ import imdb
import random import random
def movieFunc(): def movieFunc():
print("Running !movie") try:
print("Creating IMDb object") print("Creating IMDb object")
ia = imdb.IMDb() ia = imdb.IMDb()
print("Picking a movie") print("Picking a movie")
movs = open("movies.txt", "r") movs = open("funcs/other/movies.txt", "r")
movlist = movs.read().split("\n") movlist = movs.read().split("\n")
mov = random.choice(movlist) mov = random.choice(movlist)
movs.close() movs.close()
print("Searching") print("Searching for "+mov)
s_result = ia.search_movie(mov) s_result = ia.search_movie(mov)
print("Picking the movie") print("Getting the data")
movie = s_result[0] movie = s_result[0]
ia.update(movie) ia.update(movie)
cast = movie['cast'] cast = movie['cast']
@ -26,3 +26,6 @@ def movieFunc():
print("Successfully ran !movie") print("Successfully ran !movie")
print("") print("")
return(movie['title'], movie['plot'][0].split("::")[0], movie['cover url'].replace("150","600").replace("101","404"), pcast[:-2]) return(movie['title'], movie['plot'][0].split("::")[0], movie['cover url'].replace("150","600").replace("101","404"), pcast[:-2])
except:
print("Something bad happened...")
return("error","","","")

View File

@ -0,0 +1,2 @@
from .swchar import parseChar
from .swroll import parseRoll

View File

@ -69,5 +69,76 @@
"Weapons": {}, "Weapons": {},
"Talents": {}, "Talents": {},
"Force Powers": {} "Force Powers": {}
},
"TestUser": {
"Name": "New Character",
"Species": "",
"Career": "",
"Specialization Trees": [],
"Soak": 0,
"Wound Threshold": 0,
"Wounds": 0,
"Strain Threshold": 0,
"Strain": 0,
"Defense, Ranged": 0,
"Defense, Melee": 0,
"Force Rating": 0,
"Characteristics": {
"Brawn": 0,
"Agility": 0,
"Intellect": 0,
"Cunning": 0,
"Willpower": 0,
"Presence": 0
},
"Skills": {
"Astrogation": 0,
"Athletics": 0,
"Brawl": 0,
"Charm": 0,
"Coercion": 0,
"Computers": 0,
"Cool": 0,
"Coordination": 0,
"Core Worlds": 0,
"Discipline": 0,
"Gunnery": 0,
"Leadership": 0,
"Lightsaber": 0,
"Lore": 0,
"Mechanics": 0,
"Medicine": 0,
"Melee": 0,
"Negotiation": 0,
"Outer Rim": 0,
"Perception": 0,
"Piloting - Planetary": 0,
"Piloting - Space": 0,
"Ranged - Heavy": 0,
"Ranged - Light": 0,
"Resilience": 0,
"Skullduggery": 0,
"Stealth": 0,
"Streetwise": 0,
"Survival": 0,
"Underworld": 0,
"Vigilance": 0,
"Xenology": 0
},
"Lightsaber Characteristic": "Brawn",
"Obligations": {},
"Morality": {
"Emotional Weakness": "",
"Emotional Strength": "",
"Conflict": "",
"Morality": ""
},
"Credits": 0,
"Equipment": [],
"Armor": "",
"Critical Injuries": {},
"Weapons": {},
"Talents": {},
"Force Powers": {}
} }
} }

View File

@ -165,6 +165,11 @@ def parseChar(user : str, cmd : str):
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return "", "Character for " + user + " created" return "", "Character for " + user + " created"
else: else:
if cmd == "purge":
del data[user]
with open("funcs/swfuncs/characters.json", "w") as f:
json.dump(data,f,indent = 4)
return "", "Character for " + user + " deleted"
return "", charData(user,cmd) return "", charData(user,cmd)
def lightsaberChar(user : str): def lightsaberChar(user : str):

30
gwendolynTest.py Normal file
View File

@ -0,0 +1,30 @@
import unittest
import funcs
class testSwChar(unittest.TestCase):
def testNewChar(self):
text1, result = funcs.parseChar("TestUser","")
self.assertEqual(result,"Character for TestUser created")
def testChangeName(self):
text1, result = funcs.parseChar("TestUser","name TestChar")
self.assertEqual(result,"Changed TestChar's Name to TestChar")
def testChangeChar(self):
text1, result = funcs.parseChar("TestUser","characteristics brawn 1")
self.assertEqual(result,"Changed New Character's Characteristics")
def testDelChar(self):
text1, result = funcs.parseChar("TestUser","purge")
self.assertEqual(result,"Character for TestUser deleted")
class testGwendolynFuncs(unittest.TestCase):
def testCap(self):
self.assertEqual(funcs.cap("planet of the apes"),"Planet of the Apes")
self.assertEqual(funcs.cap("the greatest showman"),"The Greatest Showman")
self.assertEqual(funcs.cap("i'm the best person!"),"I'm the Best Person!")
if __name__ == "__main__":
unittest.main()