aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml7
-rwxr-xr-xcardbase.py14
-rwxr-xr-xfulltest.sh2
-rwxr-xr-xtest_callow.py22
-rwxr-xr-xtest_sorin.py58
5 files changed, 76 insertions, 27 deletions
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..c75f59f
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,7 @@
+language: python
+python:
+ - "3.4"
+# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
+install: pip install lxml requests
+# command to run tests, e.g. python setup.py test
+script: python -m unittest test_shivandragon test_callow test_cardclass test_sorin
diff --git a/cardbase.py b/cardbase.py
index 541e493..142c5a5 100755
--- a/cardbase.py
+++ b/cardbase.py
@@ -90,15 +90,21 @@ def getRarity(page):
def getPower(page):
power = extractSubTitle(page)
- power = re.search("([0-9X\*]+)/[0-9X\*]+", power).group(1)
+ power = re.search("([0-9X\*]+)/[0-9X\*]+", power)
- return power
+ if power:
+ return power.group(1)
+ else:
+ return ""
def getToughness(page):
toughness = extractSubTitle(page)
- toughness = re.search("[0-9X\*]+/([0-9X\*]+)", toughness).group(1)
+ toughness = re.search("[0-9X\*]+/([0-9X\*]+)", toughness)
- return toughness
+ if toughness:
+ return toughness.group(1)
+ else:
+ return ""
def getLoyalty(page):
loyalty = extractSubTitle(page)
diff --git a/fulltest.sh b/fulltest.sh
index 323fe10..202eb5e 100755
--- a/fulltest.sh
+++ b/fulltest.sh
@@ -1,3 +1,3 @@
#!/usr/bin/env zsh
-python -m unittest test_shivandragon test_callow test_cardclass
+python -m unittest test_shivandragon test_callow test_cardclass test_sorin
diff --git a/test_callow.py b/test_callow.py
index f19f3dc..72d25ff 100755
--- a/test_callow.py
+++ b/test_callow.py
@@ -49,28 +49,6 @@ class Test_cardInformationParsing(unittest.TestCase):
def test_correctLoyaltyIsParsed(self):
self.assertEqual(cardbase.getLoyalty(self.page), "")
-class Test_additionalCardData(unittest.TestCase):
-
- @classmethod
- def setUpClass(cls):
- cls.card = cardbase.fetchCard("bok", "31a")
-
- def test_cardHasCorrectEdition(self):
- self.assertEqual(self.card.edition, "bok")
-
- def test_cardHasCorrectScan(self):
- self.assertEqual(self.card.scan, "http://magiccards.info/scans/en/bok/31a.jpg")
-
- def test_cardHasCorrectNumber(self):
- self.assertEqual(self.card.number, "31a")
-
-
-class Test_cardPageFetching(unittest.TestCase):
-
- # Tests
- def test_correctUrlIsBuilt(self):
- self.assertEqual(cardbase.makeUrl("bok", "31a"), "http://magiccards.info/bok/en/31a.html")
-
def test():
unittest.main(exit=False)
diff --git a/test_sorin.py b/test_sorin.py
new file mode 100755
index 0000000..5ae732b
--- /dev/null
+++ b/test_sorin.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+
+import sys
+import unittest
+import cardbase
+from lxml import html
+
+
+class Test_cardInformationParsing(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ with open("sorin", "r") as file:
+ cls.page = html.fromstring(file.read())
+
+ # Tests
+ def test_correctTitleIsParsed(self):
+ self.assertEqual(cardbase.getTitle(self.page), "Sorin Markov")
+
+ def test_correctCostIsParsed(self):
+ self.assertEqual(cardbase.getCost(self.page), "3BBB")
+
+ def test_correctColourIsParsed(self):
+ self.assertEqual(cardbase.getColour(self.page), "B")
+
+ def test_correctTypeIsParsed(self):
+ self.assertEqual(cardbase.getType(self.page), "Planeswalker")
+
+ def test_correctSubTypeIsParsed(self):
+ self.assertEqual(cardbase.getSubType(self.page), "Sorin")
+
+ def test_correctArtistIsParsed(self):
+ self.assertEqual(cardbase.getArtist(self.page), "Michael Komarck")
+
+ def test_correctTextIsParsed(self):
+ self.assertEqual(cardbase.getText(self.page), ["+2: Sorin Markov deals 2 damage to target creature or player and you gain 2 life.", "−3: Target opponent's life total becomes 10.", "−7: You control target player during that player's next turn."])
+
+ def test_correctFlavourIsParsed(self):
+ self.assertEqual(cardbase.getFlavour(self.page), "")
+
+ def test_correctRarityIsParsed(self):
+ self.assertEqual(cardbase.getRarity(self.page), "Mythic Rare")
+
+ def test_correctPowerIsParsed(self):
+ self.assertEqual(cardbase.getPower(self.page), "")
+
+ def test_correctToughnessIsParsed(self):
+ self.assertEqual(cardbase.getToughness(self.page), "")
+
+ def test_correctLoyaltyIsParsed(self):
+ self.assertEqual(cardbase.getLoyalty(self.page), "4")
+
+def test():
+ unittest.main(exit=False)
+
+# The entry point
+if __name__ == "__main__":
+ test()