def test_run_filter_pcs(self):
        """Test running filters on a Phyiscal card Set"""
        make_set_1()
        dResults = run_filter("Clan = 'Ahrimane'", 'Test Set 1')
        self.assertEqual(len(dResults), 1)
        oCard = list(dResults)[0]
        self.assertEqual(dResults[oCard], 2)
        self.assertEqual(oCard.name, 'The Siamese (Group 2)')

        dResults = run_filter("Discipline = 'Potence'", 'Test Set 1')
        self.assertEqual(len(dResults), 2)
        dNameResults = {x.name: dResults[x] for x in dResults}
        self.assertEqual(dNameResults['Hektor (Group 4)'], 1)
        self.assertEqual(dNameResults['Immortal Grapple'], 4)
    def test_deck_writer(self):
        """Test CSV deck writing"""
        self.maxDiff = None
        oPhysCardSet1 = make_set_1()

        # Check output

        oWriter = WriteCSV(True, True)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sData, EXPECTED_1)

        oWriter = WriteCSV(False, True)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sData, EXPECTED_2)

        oWriter = WriteCSV(True, False)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sData, EXPECTED_3)

        oWriter = WriteCSV(False, False)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sData, EXPECTED_4)
Beispiel #3
0
    def test_roundtrip(self):
        """Test we can round-trip a deck"""
        self.maxDiff = None
        oPhysCardSet1 = make_set_1()
        oParser = ARDBTextParser()

        oWriter = WriteArdbText()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        oHolder = self._make_holder_from_string(oParser, sData)

        self.assertEqual(oHolder.name, oPhysCardSet1.name)
        self.assertEqual(oHolder.author, oPhysCardSet1.author)
        self.assertEqual(oHolder.comment.strip(), oPhysCardSet1.comment)

        aCards = oHolder.get_cards()
        dSetCards = {}
        # Reformat cards in deck to match holder
        # pylint: disable=not-an-iterable
        # SQLObject confuses pylint
        for sName in [x.abstractCard.name for x in oPhysCardSet1.cards]:
            # We truncate Inez here to match the writer output
            if sName.startswith('Inez'):
                sName = sName[:18]
            sName = strip_group_from_name(sName)
            dSetCards.setdefault(sName, 0)
            dSetCards[sName] += 1
        # pylint: enable=not-an-iterable

        for sName, iCnt in dSetCards.items():
            self.assertTrue((sName, iCnt) in aCards)
    def test_deck_writer(self):
        """Test HTML deck writing"""
        self.maxDiff = None
        oPhysCardSet1 = make_set_1()

        sCurDate = time.strftime('[ %Y-%m-%d ]', time.localtime())
        # Check output

        oWriter = WriteArdbHTML(bDoText=False)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))
        sData = sData.replace(sCurDate, '[ DATE ]')

        self._compare_xml_strings(sData, EXPECTED_1)

        # Test other modes
        oWriter = WriteArdbHTML('Codex of the Damned', True)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))
        sData = sData.replace(sCurDate, '[ DATE ]')

        self._compare_xml_strings(sData, EXPECTED_2)

        oWriter = WriteArdbHTML('None', False)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))
        sData = sData.replace(sCurDate, '[ DATE ]')

        self._compare_xml_strings(sData, EXPECTED_3)
Beispiel #5
0
    def test_deck_writer(self):
        """Test CSV deck writing"""
        oPhysCardSet1 = make_set_1()

        # Check output

        oWriter = WriteCSV(True, True)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sData, EXPECTED_1)

        oWriter = WriteCSV(False, True)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sData, EXPECTED_2)

        oWriter = WriteCSV(True, False)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sData, EXPECTED_3)

        oWriter = WriteCSV(False, False)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sData, EXPECTED_4)
    def test_roundtrip(self):
        """Test we can round-trip a deck"""
        oPhysCardSet1 = make_set_1()
        oParser = ARDBTextParser()

        oWriter = WriteArdbText()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        oHolder = self._make_holder_from_string(oParser, sData)

        self.assertEqual(oHolder.name, oPhysCardSet1.name)
        self.assertEqual(oHolder.author, oPhysCardSet1.author)
        self.assertEqual(oHolder.comment.strip(), oPhysCardSet1.comment)

        aCards = oHolder.get_cards()
        dSetCards = {}
        # Reformat cards in deck to match holder
        for sName in [x.abstractCard.name for x in oPhysCardSet1.cards]:
            # We truncate Inez here to match the writer output
            if sName.startswith('Inez'):
                sName = sName[:18]
            dSetCards.setdefault(sName, 0)
            dSetCards[sName] += 1

        for sName, iCnt in dSetCards.iteritems():
            self.failUnless((sName, iCnt) in aCards)
    def test_physical_card_set_writer(self):
        """Test physical card set writing"""
        # pylint: disable-msg=E1101, R0915, R0914
        # E1101: SQLObject + PyProtocols magic confuses pylint
        # R0915, R0914: Want a long, sequential test case to minimise
        # repeated setups, so it has lots of lines + variables
        aAddedPhysCards = get_phys_cards()
        # We have a physical card list, so create some physical card sets
        oPhysCardSet1 = make_set_1()

        # Check output

        oWriter = PhysicalCardSetWriter()
        oFile = StringIO()
        oWriter.write(oFile, CardSetWrapper(oPhysCardSet1))
        sWriterXML = oFile.getvalue()
        oFile.close()
        self.assertEqual(sWriterXML, EXPECTED_1)
        self.assertEqual(len(sWriterXML), len(EXPECTED_1))

        oPCS = IPhysicalCardSet(CARD_SET_NAMES[0])
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPCS))
        self.assertEqual(sData, sWriterXML)
        self.assertEqual(len(sData), len(EXPECTED_1))
        self.assertEqual(sData, EXPECTED_1)

        oPhysCardSet2 = PhysicalCardSet(name=CARD_SET_NAMES[1])
        oPhysCardSet2.author = 'A test author'
        oPhysCardSet2.comment = 'A formatted test comment\nA second line\n' \
                'A third line'
        oPhysCardSet2.annotations = 'Some Annotations'

        for iLoop in range(5, 10):
            oPhysCardSet2.addPhysicalCard(aAddedPhysCards[iLoop].id)
            oPhysCardSet2.syncUpdate()

        oFile = StringIO()
        oWriter.write(oFile, CardSetWrapper(oPhysCardSet2))
        sWriterXML = oFile.getvalue()
        oFile.close()
        self.assertEqual(len(sWriterXML), len(EXPECTED_2))
        self.assertEqual(sWriterXML, EXPECTED_2)

        sTempFileName = self._create_tmp_file()
        oFileXML = PhysicalCardSetXmlFile(sTempFileName)
        oFileXML.write(CARD_SET_NAMES[1])
        fIn = open(sTempFileName, 'rU')
        sData = fIn.read()
        self.assertEqual(len(sData), len(EXPECTED_2))
        self.assertEqual(sData, EXPECTED_2)

        # Unset the author
        oPhysCardSet2.author = None
        oFile = StringIO()
        oWriter.write(oFile, CardSetWrapper(oPhysCardSet2))
        sWriterXML = oFile.getvalue()
        oFile.close()
        self.assertEqual(len(sWriterXML), len(EXPECTED_3))
        self.assertEqual(sWriterXML, EXPECTED_3)
Beispiel #8
0
    def test_deck_writer(self):
        """Test JOL deck writing"""
        oPhysCardSet1 = make_set_1()

        # Check output

        oWriter = WriteJOL()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sData, EXPECTED_1)
    def test_deck_writer(self):
        """Test ARDB text file writing"""
        oPhysCardSet1 = make_set_1()

        # Check output

        oWriter = WriteArdbText()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sData, ARDB_TEXT_EXPECTED_1)
Beispiel #10
0
    def test_deck_writer(self):
        """Test TWDA text file writing"""
        self.maxDiff = None
        oPhysCardSet = make_set_1()

        # Check output
        oWriter = WriteTWDAText()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet))

        self.assertEqual(sData, TWDA_EXPECTED_1)
    def test_physical_card_set_writer(self):
        """Test physical card set writing"""
        self.maxDiff = None
        # pylint: disable=too-many-statements, too-many-locals
        # Want a long, sequential test case to minimise
        # repeated setups, so it has lots of lines + variables
        # We have a physical card list, so create some physical card sets
        oPhysCardSet1 = make_set_1()

        # Check output

        oWriter = PhysicalCardSetWriter()
        oFile = StringIO()
        oWriter.write(oFile, CardSetWrapper(oPhysCardSet1))
        sWriterXML = oFile.getvalue()
        oFile.close()
        self._compare_xml_strings(sWriterXML, EXPECTED_1)

        oPCS = IPhysicalCardSet(CARD_SET_NAMES[0])
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPCS))
        self._compare_xml_strings(sData, sWriterXML)
        self._compare_xml_strings(sData, EXPECTED_1)

        oPhysCardSet2 = make_set_2()

        oFile = StringIO()
        oWriter.write(oFile, CardSetWrapper(oPhysCardSet2))
        sWriterXML = oFile.getvalue()
        oFile.close()
        self._compare_xml_strings(sWriterXML, EXPECTED_2)

        sTempFileName = self._create_tmp_file()
        oFileXML = PhysicalCardSetXmlFile(sTempFileName)
        oFileXML.write(CARD_SET_NAMES[1])
        fIn = open(sTempFileName, 'r')
        sData = fIn.read()
        self._compare_xml_strings(sData, EXPECTED_2)

        # Unset the author
        oPhysCardSet2.author = None
        oFile = StringIO()
        oWriter.write(oFile, CardSetWrapper(oPhysCardSet2))
        sWriterXML = oFile.getvalue()
        oFile.close()
        self._compare_xml_strings(sWriterXML, EXPECTED_3)

        # Test with more unicode stuff
        oWriter = PhysicalCardSetWriter()

        oPhysCardSet3 = make_set_3()
        oFile = StringIO()
        oWriter.write(oFile, CardSetWrapper(oPhysCardSet3))
        sWriterXML = oFile.getvalue()
        oFile.close()
        self._compare_xml_strings(sWriterXML, EXPECTED_4)
Beispiel #12
0
    def test_deck_writer(self):
        """Test ARDB text file writing"""
        self.maxDiff = None
        oPhysCardSet1 = make_set_1()

        # Check output

        oWriter = WriteArdbText()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sData, ARDB_TEXT_EXPECTED_1)
Beispiel #13
0
    def test_deck_writer(self):
        """Test ELDB deck writing"""
        self.maxDiff = None
        oPhysCardSet1 = make_set_1()

        # Check output

        oWriter = WriteELDBDeckFile()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sData, EXPECTED_1)
Beispiel #14
0
    def test_deck_writer(self):
        """Test ARDB XML deck writing"""
        oPhysCardSet1 = make_set_1()
        sCurDate = time.strftime('>%Y-%m-%d<', time.localtime())

        # Check output

        oWriter = WriteArdbXML()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))
        sData = sData.replace(sCurDate, '>DATE<')

        self.assertEqual(sData, EXPECTED_1)
    def test_inventory_writer(self):
        """Test ELDB inventory writing"""
        oPhysCardSet1 = make_set_1()

        # Check output

        oWriter = WriteELDBInventory()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sorted(sData.splitlines()),
                sorted(EXPECTED.splitlines()), "Output differs : "
                "%s vs %s" % (sorted(sData.splitlines()),
                    sorted(EXPECTED.splitlines())))
    def test_deck_writer(self):
        """Test VEKN bbcode file writing"""
        self.maxDiff = None
        oPhysCardSet1 = make_set_1()

        sCurDate = time.strftime('[ %Y-%m-%d ]', time.localtime())

        # Check output
        oWriter = WriteVEKNForum()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))
        sData = sData.replace(sCurDate, '[ DATE ]')

        self.assertEqual(sData, VEKN_EXPECTED_1)
Beispiel #17
0
    def test_deck_writer(self):
        """Test ARDB XML deck writing"""
        self.maxDiff = None
        oPhysCardSet1 = make_set_1()
        sCurDate = time.strftime('>%Y-%m-%d<', time.localtime())

        # Check output

        oWriter = WriteArdbXML()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))
        sData = sData.replace(sCurDate, '>DATE<')

        self._compare_xml_strings(sData, EXPECTED_1)
    def test_inventory_writer(self):
        """Test ELDB inventory writing"""
        self.maxDiff = None
        oPhysCardSet1 = make_set_1()

        # Check output

        oWriter = WriteELDBInventory()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(
            sorted(sData.splitlines()), sorted(EXPECTED.splitlines()),
            "Output differs : %s vs %s" %
            (sorted(sData.splitlines()), sorted(EXPECTED.splitlines())))
Beispiel #19
0
    def test_deck_writer(self):
        """Test Lackey CCG deck writing"""
        self.maxDiff = None
        oPhysCardSet1 = make_set_1()

        # Check output

        oWriter = WriteLackeyCCG()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))

        self.assertEqual(sData, EXPECTED_1)

        oPhysCardSet2 = make_set_2()
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet2))

        self.assertEqual(sData, EXPECTED_2)
Beispiel #20
0
    def test_card_set_parser_ver1_4(self):
        """Test physical card set reading for a version 1.4 card set"""
        self.maxDiff = None
        oParser = PhysicalCardSetParser()

        oHolder = CardSetHolder()
        oParser.parse(StringIO(PCS_EXAMPLE_VER_1_4), oHolder)
        oHolder.create_pcs()

        oPhysCardSet14 = IPhysicalCardSet("Test Set 1.4")
        self.assertEqual(len(oPhysCardSet14.cards), 34)

        self.assertEqual(oPhysCardSet14.comment, 'A test comment')

        oOrig = make_set_1()
        oOrig.name = 'Original for 1.4 test'
        # pylint: disable=not-an-iterable
        # SQLObject confuses pylint here
        for oCard in oOrig.cards:
            self.assertTrue(
                oCard in oPhysCardSet14.cards, "%s and %s differ on card %s" %
                (oPhysCardSet14.name, oOrig.name, oCard.abstractCard.name))
Beispiel #21
0
    def test_deck_writer(self):
        """Test HTML deck writing"""
        oPhysCardSet1 = make_set_1()

        sCurDate = time.strftime('[ %Y-%m-%d ]', time.localtime())
        # Check output

        oWriter = WriteArdbHTML(bDoText=False)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))
        sData = sData.replace(sCurDate, '[ DATE ]')

        self.assertEqual(sData, EXPECTED_1)

        # Test other modes
        oWriter = WriteArdbHTML('Monger', False)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))
        sData = sData.replace(sCurDate, '[ DATE ]')

        self.assertEqual(sData, EXPECTED_1)

        oWriter = WriteArdbHTML('None', False)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))
        sData = sData.replace(sCurDate, '[ DATE ]')

        self.assertEqual(sData, EXPECTED_2)

        oWriter = WriteArdbHTML('Secret Library', False)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))
        sData = sData.replace(sCurDate, '[ DATE ]')

        self.assertEqual(sData, EXPECTED_3)

        oWriter = WriteArdbHTML('Secret Library', True)
        sData = self._round_trip_obj(oWriter, CardSetWrapper(oPhysCardSet1))
        sData = sData.replace(sCurDate, '[ DATE ]')

        self.assertEqual(sData, EXPECTED_4)