Esempio n. 1
0
def test_rows_for_cards_verbose(oracle: Oracle) -> None:
    card_counts: ScryfallCardCount = {TEST_CARD_ID: {counts.CountType.nonfoil: 3}}
    collection = MagicCollection(oracle=oracle, counts=card_counts)
    rows = csv.rows_for_cards(collection, True)
    assert list(rows) == [
        {
            "set": "PHOP",
            "name": "Stairs to Infinity",
            "collector_number": "P1",
            "scryfall_id": TEST_CARD_ID,
            "nonfoil": 3,
        },
        {
            "collector_number": "41",
            "name": "Tazeem",
            "scryfall_id": UUID("76e5383d-ac12-4abc-aa30-15e99ded2d6f"),
            "set": "PHOP",
        },
        {
            "set": "PMBS",
            "name": "Black Sun's Zenith",
            "collector_number": "39",
            "scryfall_id": UUID("dd88131a-2811-4a1f-bb9a-c82e12c1493b"),
        },
    ]
Esempio n. 2
0
 def read(self, path: Path, oracle: Oracle) -> MagicCollection:
     """Read collection from an xlsx file."""
     workbook = openpyxl.load_workbook(filename=str(path), read_only=True)
     reader = rows_for_workbook(workbook,
                                skip_sheets={"All Sets", "All Cards"})
     card_counts = counts.aggregate_card_counts(reader, oracle)
     return MagicCollection(oracle=oracle, counts=card_counts)
Esempio n. 3
0
File: ssm.py Progetto: gwax/mtg_ssm
def merge_cmd(args: argparse.Namespace, oracle: Oracle) -> None:
    """Merge counts from one or more inputs into a new/existing collection."""
    coll_serializer = get_serializer(args.dialect, args.collection)
    collection = MagicCollection(oracle=oracle, counts={})
    if args.collection.exists():
        print(f"Reading counts from {args.collection}")
        collection = coll_serializer.read(args.collection, oracle)
    for import_path in args.imports:
        input_serializer = get_serializer(args.dialect, import_path)
        print(f"Merging counts from {import_path}")
        collection += input_serializer.read(import_path, oracle)
    write_file(coll_serializer, collection, args.collection)
Esempio n. 4
0
def test_rows_for_cards_terse(oracle: Oracle) -> None:
    card_counts: counts.ScryfallCardCount = {
        TEST_CARD_ID: {counts.CountType.nonfoil: 3}
    }
    collection = MagicCollection(oracle=oracle, counts=card_counts)
    rows = csv.rows_for_cards(collection, False)
    assert list(rows) == [
        {
            "set": "PHOP",
            "name": "Stairs to Infinity",
            "collector_number": "P1",
            "scryfall_id": TEST_CARD_ID,
            "nonfoil": 3,
        }
    ]
Esempio n. 5
0
def test_write_terse(oracle: Oracle, tmp_path: Path) -> None:
    csv_path = tmp_path / "outfile.csv"
    card_counts: counts.ScryfallCardCount = {
        TEST_CARD_ID: {counts.CountType.nonfoil: 3}
    }
    collection = MagicCollection(oracle=oracle, counts=card_counts)

    serializer = csv.CsvTerseDialect()
    serializer.write(csv_path, collection)
    with csv_path.open("rt", encoding="utf-8") as csv_file:
        assert csv_file.read() == textwrap.dedent(
            """\
            set,name,collector_number,scryfall_id,nonfoil,foil
            PHOP,Stairs to Infinity,P1,57f25ead-b3ec-4c40-972d-d750ed2f5319,3,
            """
        )
Esempio n. 6
0
def test_write(oracle: Oracle, tmp_path: Path) -> None:
    xlsx_path = tmp_path / "outfile.xlsx"
    card_counts: ScryfallCardCount = {
        UUID("5d5f3f57-410f-4ee2-b93c-f5051a068828"): {
            CountType.nonfoil: 7,
            CountType.foil: 12,
        }
    }
    collection = MagicCollection(oracle=oracle, counts=card_counts)

    serializer = xlsx.XlsxDialect()
    serializer.write(xlsx_path, collection)

    workbook = openpyxl.load_workbook(filename=xlsx_path)
    assert workbook.sheetnames == [
        "All Sets",
        "All Cards",
        "LEA",
        "FEM",
        "ICE",
        "S00",
        "HOP",
    ]

    s00_rows = [[cell.value for cell in row] for row in workbook["S00"]]
    assert s00_rows == [
        [
            "have",
            "name",
            "scryfall_id",
            "collector_number",
            "artist",
            "nonfoil",
            "foil",
            "others",
        ],
        [
            "=F2+G2",
            "Rhox",
            "5d5f3f57-410f-4ee2-b93c-f5051a068828",
            "43",
            "Mark Zug",
            7,
            12,
            None,
        ],
    ]
Esempio n. 7
0
def test_write_verbose(oracle: Oracle, tmp_path: Path) -> None:
    csv_path = tmp_path / "outfile.csv"
    card_counts: ScryfallCardCount = {
        TEST_CARD_ID: {counts.CountType.nonfoil: 3, counts.CountType.foil: 7}
    }
    collection = MagicCollection(oracle=oracle, counts=card_counts)
    serializer = csv.CsvFullDialect()
    serializer.write(csv_path, collection)
    with csv_path.open("rt", encoding="utf-8") as csv_file:
        assert csv_file.read() == textwrap.dedent(
            """\
            set,name,collector_number,scryfall_id,nonfoil,foil
            PHOP,Stairs to Infinity,P1,57f25ead-b3ec-4c40-972d-d750ed2f5319,3,7
            PHOP,Tazeem,41,76e5383d-ac12-4abc-aa30-15e99ded2d6f,,
            PMBS,Black Sun\'s Zenith,39,dd88131a-2811-4a1f-bb9a-c82e12c1493b,,
            """
        )
Esempio n. 8
0
File: csv.py Progetto: gwax/mtg_ssm
 def read(self, path: Path, oracle: Oracle) -> MagicCollection:
     """Read collection from file."""
     with path.open("rt", encoding="utf-8") as csv_file:
         reader = csv.DictReader(csv_file)
         card_counts = counts.aggregate_card_counts(reader, oracle)
     return MagicCollection(oracle=oracle, counts=card_counts)
Esempio n. 9
0
def test_create_set_sheet(oracle: Oracle) -> None:
    card_counts: ScryfallCardCount = {
        UUID("fbdcbd97-90a9-45ea-94f6-2a1c6faaf965"): {
            CountType.nonfoil: 1
        },
        UUID("b346b784-7bde-49d0-bfa9-56236cbe19d9"): {
            CountType.foil: 2
        },
        UUID("768c4d8f-5700-4f0a-9ff2-58422aeb1dac"): {
            CountType.nonfoil: 3,
            CountType.foil: 4,
        },
    }
    collection = MagicCollection(oracle=oracle, counts=card_counts)
    book = openpyxl.Workbook()
    sheet = book.create_sheet()
    xlsx.create_set_sheet(sheet, collection, "ice")
    assert sheet.title == "ICE"
    rows = [[cell.value for cell in row] for row in sheet.rows]
    assert rows == [
        [
            "have",
            "name",
            "scryfall_id",
            "collector_number",
            "artist",
            "nonfoil",
            "foil",
            "others",
        ],
        [
            "=F2+G2",
            "Dark Ritual",
            "4ebcd681-1871-4914-bcd7-6bd95829f6e0",
            "120",
            "Justin Hampton",
            None,
            None,
            mock.ANY,
        ],
        [
            "=F3+G3",
            "Forest",
            "fbdcbd97-90a9-45ea-94f6-2a1c6faaf965",
            "380",
            "Pat Morrissey",
            1,
            None,
            mock.ANY,
        ],
        [
            "=F4+G4",
            "Forest",
            "b346b784-7bde-49d0-bfa9-56236cbe19d9",
            "381",
            "Pat Morrissey",
            None,
            2,
            mock.ANY,
        ],
        [
            "=F5+G5",
            "Forest",
            "768c4d8f-5700-4f0a-9ff2-58422aeb1dac",
            "382",
            "Pat Morrissey",
            3,
            4,
            mock.ANY,
        ],
        [
            "=F6+G6",
            "Snow-Covered Forest",
            "4c0ad95c-d62c-4138-ada0-fa39a63a449e",
            "383",
            "Pat Morrissey",
            None,
            None,
            mock.ANY,
        ],
    ]
Esempio n. 10
0
File: ssm.py Progetto: gwax/mtg_ssm
def create_cmd(args: argparse.Namespace, oracle: Oracle) -> None:
    """Create a new, empty collection."""
    collection = MagicCollection(oracle=oracle, counts={})
    serializer = get_serializer(args.dialect, args.collection)
    write_file(serializer, collection, args.collection)