Beispiel #1
0
    def test_load(self):
        c = StringIO.StringIO(json.dumps(self.deck))
        c.name = "Foo Deck.deck"
        self.assertEqual(d.load(file=c), self.deck)

        # mtgo
        c = StringIO.StringIO(self.mtgo)
        c.name = "Foo Deck.txt"
        self.assertEqual(d.load(file=c), self.export_deck_loaded)

        # apprentice
        c = StringIO.StringIO(self.mtgo)
        c.name = "Foo Deck.dec"
        self.assertEqual(d.load(file=c), self.export_deck_loaded)

        with self.assertRaises(ValueError):
            d.load(file=c, format="invalid_thing")
Beispiel #2
0
    def test_load(self):
        c = StringIO.StringIO(json.dumps(self.deck))
        c.name = "Foo Deck.deck"
        self.assertEqual(d.load(file=c), self.deck)

        # mtgo
        c = StringIO.StringIO(self.mtgo)
        c.name = "Foo Deck.txt"
        self.assertEqual(d.load(file=c), self.export_deck_loaded)

        # apprentice
        c = StringIO.StringIO(self.mtgo)
        c.name = "Foo Deck.dec"
        self.assertEqual(d.load(file=c), self.export_deck_loaded)

        with self.assertRaises(ValueError):
            d.load(file=c, format="invalid_thing")
Beispiel #3
0
    def test_save(self):
        m = mock.Mock(side_effect=lambda name : name)
        to = StringIO.StringIO()

        d.save("Foo Deck", self.deck, to)
        in_file = StringIO.StringIO(to.getvalue())
        in_file.name = "Foo Deck.deck"
        self.assertEqual(d.load(file=in_file), self.deck)

        # saving to default directory
        with mock.patch(d.__name__ + ".open", create=True) as mock_open:
            mock_open.return_value = mock.MagicMock(spec=file)
            mock_open.return_value.__enter__.return_value = StringIO.StringIO()

            with mock.patch(d.__name__ + ".DECKS_DIR", "bar"):
                d.save("Foo Deck", self.deck)
                to = mock_open.return_value.__enter__.return_value

        in_file = StringIO.StringIO(to.getvalue())
        in_file.name = "Foo Deck.deck"
        self.assertEqual(d.load(file=in_file), self.deck)

        path = os.path.join("bar", "Foo Deck.deck")
        mock_open.assert_called_once_with(path, "w")
Beispiel #4
0
    def test_save(self):
        m = mock.Mock(side_effect=lambda name: name)
        to = StringIO.StringIO()

        d.save("Foo Deck", self.deck, to)
        in_file = StringIO.StringIO(to.getvalue())
        in_file.name = "Foo Deck.deck"
        self.assertEqual(d.load(file=in_file), self.deck)

        # saving to default directory
        with mock.patch(d.__name__ + ".open", create=True) as mock_open:
            mock_open.return_value = mock.MagicMock(spec=file)
            mock_open.return_value.__enter__.return_value = StringIO.StringIO()

            with mock.patch(d.__name__ + ".DECKS_DIR", "bar"):
                d.save("Foo Deck", self.deck)
                to = mock_open.return_value.__enter__.return_value

        in_file = StringIO.StringIO(to.getvalue())
        in_file.name = "Foo Deck.deck"
        self.assertEqual(d.load(file=in_file), self.deck)

        path = os.path.join("bar", "Foo Deck.deck")
        mock_open.assert_called_once_with(path, "w")