def test_abstract_cs_parser(self): """Test abstract card set parser""" # Support for everything except reading has been removed. # It is expected that reading in an ACS will create an # equivalent PCS. self.maxDiff = None oParser = AbstractCardSetParser() sTempFileName = self._create_tmp_file() fOut = open(sTempFileName, 'w') fOut.write(ACS_EXAMPLE_1) fOut.close() oHolder = CardSetHolder() oParser.parse(StringIO(ACS_EXAMPLE_2), oHolder) oHolder.create_pcs() fIn = open(sTempFileName, 'r') oHolder = CardSetHolder() oParser.parse(fIn, oHolder) oHolder.create_pcs() fIn.close() oCardSet1 = IPhysicalCardSet("(ACS) " + CARD_SET_NAMES[0]) oCardSet2 = IPhysicalCardSet("(ACS) " + CARD_SET_NAMES[1]) oPhysCard0 = make_card(ABSTRACT_CARDS[0][0], None) oPhysCard2 = make_card(ABSTRACT_CARDS[2][0], None) self.assertEqual(len(oCardSet1.cards), 5) self.assertEqual(len(oCardSet2.cards), 9) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=oPhysCard0.id).count(), 3) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=oPhysCard2.id).count(), 2) PhysicalCardSet.delete(oCardSet1.id) oFile = AbstractCardSetXmlFile() self.assertRaises(IOError, oFile.read) oFile = AbstractCardSetXmlFile(sTempFileName) oFile.read() oCardSet1 = IPhysicalCardSet("(ACS) Test Set 1") self.assertEqual(len(oCardSet1.cards), 5) oFile.delete() self.assertFalse(os.path.exists(sTempFileName)) self.assertRaises(RuntimeError, oFile.write, '(ACS) Test Set 1') oHolder = CardSetHolder() self.assertRaises(IOError, oParser.parse, StringIO('<caarrd>%s</caarrd>' % ACS_EXAMPLE_1), oHolder)
def test_physical(self): """Test physical card handling""" # test IO self.maxDiff = None sExample = make_example_pcxml() oParser = PhysicalCardParser() oHolder = CardSetHolder() oParser.parse(StringIO(sExample), oHolder) oHolder.create_pcs() oMyCollection = IPhysicalCardSet("My Collection") self.assertEqual(len(oMyCollection.cards), 1) PhysicalCardSet.delete(oMyCollection.id) sTempFileName = self._create_tmp_file() fOut = open(sTempFileName, 'w') fOut.write(sExample) fOut.close() fIn = open(sTempFileName, 'r') oHolder = CardSetHolder() oParser.parse(fIn, oHolder) fIn.close() oHolder.create_pcs() # Test incorrect input oHolder = CardSetHolder() self.assertRaises( IOError, oParser.parse, StringIO('<ccaardd sutekh_xml_version="1.0"><card' ' count="1" expansion="None Specified"' ' id="12" name="Abbot" /></ccaardd>'), oHolder) self.assertRaises( IOError, oParser.parse, StringIO('<cards sutekh_xml_version="5.0"><card' ' count="1" expansion="None Specified"' ' id="12" name="Abbot" /></cards>'), oHolder) # Check read results oMyCollection = IPhysicalCardSet("My Collection") self.assertEqual(len(oMyCollection.cards), 1) PhysicalCardSet.delete(oMyCollection.id) oFile = PhysicalCardXmlFile(sTempFileName) oFile.read() oMyCollection = IPhysicalCardSet("My Collection") self.assertEqual(len(oMyCollection.cards), 1) oFile.delete() self.assertFalse(os.path.exists(sTempFileName)) self.assertRaises(RuntimeError, oFile.write)
def test_physical_card_set_parser(self): """Test physical card set reading""" 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 aAddedPhysCards = get_phys_cards() # We have a physical card list, so create some physical card sets # Check input oParser = PhysicalCardSetParser() oHolder = CardSetHolder() oParser.parse(StringIO(PCS_EXAMPLE_1), oHolder) oHolder.create_pcs() sTempFileName = self._create_tmp_file() fIn = open(sTempFileName, 'w') fIn.write(PCS_EXAMPLE_2) fIn.close() fIn = open(sTempFileName, 'r') oHolder = CardSetHolder() oParser.parse(fIn, oHolder) oHolder.create_pcs() fIn.close() oHolder = CardSetHolder() oParser.parse(StringIO(PCS_EXAMPLE_3), oHolder) oHolder.create_pcs() oPhysCardSet1 = IPhysicalCardSet(CARD_SET_NAMES[0]) oPhysCardSet2 = IPhysicalCardSet(CARD_SET_NAMES[1]) oPhysCardSet3 = IPhysicalCardSet(CARD_SET_NAMES[2]) self.assertEqual(len(oPhysCardSet1.cards), 5) self.assertEqual(len(oPhysCardSet2.cards), 8) self.assertEqual(len(oPhysCardSet3.cards), 7) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[0].id).count(), 1) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[7].id).count(), 2) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[4].id).count(), 3) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[1].id).count(), 1) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[6].id).count(), 3) # Aaron's Feeding razor self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[14].id).count(), 0) # Inez self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[12].id).count(), 0) PhysicalCardSet.delete(oPhysCardSet2.id) oFile = PhysicalCardSetXmlFile() self.assertRaises(IOError, oFile.read) oFile = PhysicalCardSetXmlFile(sTempFileName) oFile.read() oPhysCardSet2 = IPhysicalCardSet("Test Set 2") self.assertEqual(len(oPhysCardSet2.cards), 8) oFile.delete() self.assertFalse(os.path.exists(sTempFileName)) oFile.write('Test Set 2') PhysicalCardSet.delete(oPhysCardSet2.id) self.assertTrue(os.path.exists(sTempFileName)) oFile.read() oPhysCardSet2 = IPhysicalCardSet("Test Set 2") self.assertEqual(len(oPhysCardSet2.cards), 8) self.assertEqual(oPhysCardSet2.annotations, None) self.assertEqual(oPhysCardSet3.annotations, 'Some annotations') self.assertEqual(oPhysCardSet2.comment, 'A test comment') self.assertEqual(oPhysCardSet3.comment, 'A formatted test comment\n' 'A second line') oHolder = CardSetHolder() self.assertRaises(IOError, oParser.parse, StringIO('<caards></caards>'), oHolder)
def test_physical_card_set(self): """Test physical card set object""" # 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 aAddedPhysCards = get_phys_cards() # We have a physical card list, so create some physical card sets oPhysCardSet1 = PhysicalCardSet(name=CARD_SET_NAMES[2]) # Add cards to the physical card sets for iLoop in range(5): # pylint: disable=no-member # SQLObect confused pylint oPhysCardSet1.addPhysicalCard(aAddedPhysCards[iLoop].id) oPhysCardSet1.syncUpdate() self.assertEqual(len(oPhysCardSet1.cards), 5) # Because we repeat .44 Magnum 3 times self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[0].id).count(), 3) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[4].id).count(), 1) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[7].id).count(), 0) oPhysCardSet2 = PhysicalCardSet(name=CARD_SET_NAMES[1], comment='Test 2', author=oPhysCardSet1.author) self.assertEqual(oPhysCardSet2.name, CARD_SET_NAMES[1]) self.assertEqual(oPhysCardSet2.author, oPhysCardSet1.author) self.assertEqual(oPhysCardSet2.comment, 'Test 2') for iLoop in range(3, 8): # pylint: disable=no-member # SQLObect confused pylint oPhysCardSet2.addPhysicalCard(aAddedPhysCards[iLoop].id) oPhysCardSet2.syncUpdate() self.assertEqual(len(oPhysCardSet2.cards), 5) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[0].id).count(), 3) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[4].id).count(), 2) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[7].id).count(), 1) oPhysCardSet3 = make_set_1() self.assertEqual(len(oPhysCardSet3.cards), len(aAddedPhysCards)) self.assertEqual(oPhysCardSet3.name, CARD_SET_NAMES[0]) self.assertEqual(oPhysCardSet3.comment, 'A test comment') oPhysCardSet4 = IPhysicalCardSet(CARD_SET_NAMES[0]) self.assertEqual(oPhysCardSet3, oPhysCardSet4) # pylint: disable=no-member # SQLObject confuses pylint oPhysCardSet5 = PhysicalCardSet.byName(CARD_SET_NAMES[1]) self.assertEqual(oPhysCardSet2, oPhysCardSet5) # Check Deletion # pylint: disable=not-an-iterable # SQLOBject confuses pylint for oCard in oPhysCardSet3.cards: oPhysCardSet3.removePhysicalCard(oCard.id) # pylint: enable=not-an-iterable self.assertEqual(len(oPhysCardSet3.cards), 0) PhysicalCardSet.delete(oPhysCardSet3.id) self.assertRaises(SQLObjectNotFound, PhysicalCardSet.byName, CARD_SET_NAMES[0]) delete_physical_card_set(CARD_SET_NAMES[1]) self.assertRaises(SQLObjectNotFound, PhysicalCardSet.byName, CARD_SET_NAMES[1]) # pylint: enable=no-member self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[0].id).count(), 3) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[4].id).count(), 1) delete_physical_card_set(CARD_SET_NAMES[2]) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[0].id).count(), 0) self.assertEqual( MapPhysicalCardToPhysicalCardSet.selectBy( physicalCardID=aAddedPhysCards[4].id).count(), 0)