コード例 #1
0
ファイル: test_ssm.py プロジェクト: gwax/mtg_ssm
def test_merge_cmd_new(tmp_path: Path, oracle: Oracle) -> None:
    work_path = tmp_path / "work"
    work_path.mkdir()
    coll_path = work_path / "collection.csv"
    import_path = work_path / "import.csv"

    import_path.write_text(
        textwrap.dedent("""\
            scryfall_id,nonfoil,foil
            69d20d28-76e9-4e6e-95c3-f88c51dfabfd,4,9
            """))

    args = ap.Namespace(collection=coll_path,
                        imports=[import_path],
                        dialect={})
    ssm.merge_cmd(args, oracle)

    assert set(work_path.iterdir()) == {coll_path, import_path}
    assert coll_path.read_text() == textwrap.dedent("""\
        set,name,collector_number,scryfall_id,nonfoil,foil
        PMBS,Black Sun's Zenith,39,dd88131a-2811-4a1f-bb9a-c82e12c1493b,,
        MMA,Thallid,167,69d20d28-76e9-4e6e-95c3-f88c51dfabfd,4,9
        """)
    assert import_path.read_text() == textwrap.dedent("""\
        scryfall_id,nonfoil,foil
        69d20d28-76e9-4e6e-95c3-f88c51dfabfd,4,9
        """)
コード例 #2
0
ファイル: test_ssm.py プロジェクト: TonyRoomZ/mtg_ssm
def test_merge_cmd_new():
    with tempfile.TemporaryDirectory() as tmpdirname:
        outfilename = os.path.join(tmpdirname, "outfile.csv")
        importname = os.path.join(tmpdirname, "import.csv")
        with open(importname, "wt") as infile:
            infile.write(
                textwrap.dedent("""\
                    id,copies,foils
                    fc46a4b72d216117a352f59217a84d0baeaaacb7,4,8
                    """))
        args = get_namespace(
            action="merge",
            func=ssm.merge_cmd,
            collection=outfilename,
            imports=[importname],
        )
        ssm.merge_cmd(args)
        assert set(os.listdir(tmpdirname)) == {"import.csv", "outfile.csv"}
        with open(outfilename, "rt") as outfile:
            outfiledata = outfile.read()
        with open(importname, "rt") as importfile:
            importdata = importfile.read()
    assert outfiledata == textwrap.dedent("""\
        set,name,number,multiverseid,id,copies,foils
        pMGD,Black Sun's Zenith,7,,6c9ffa9ffd2cf7e6f85c6be1713ee0c546b9f8fc,,
        MMA,Thallid,167,370352,fc46a4b72d216117a352f59217a84d0baeaaacb7,4,8
        """)
    assert importdata == textwrap.dedent("""\
        id,copies,foils
        fc46a4b72d216117a352f59217a84d0baeaaacb7,4,8
        """)
コード例 #3
0
ファイル: test_ssm.py プロジェクト: gwax/mtg_ssm
def test_merge_cmd_multiple(tmp_path: Path, oracle: Oracle) -> None:
    work_path = tmp_path / "work"
    work_path.mkdir()
    coll_path = work_path / "collection.csv"
    import_path1 = work_path / "import1.csv"
    import_path2 = work_path / "import2.csv"
    expected_backup_path = work_path / "collection.20150628_080910.csv"

    coll_path.write_text(
        textwrap.dedent("""\
            scryfall_id,nonfoil,foil
            69d20d28-76e9-4e6e-95c3-f88c51dfabfd,1,3
            """))
    import_path1.write_text(
        textwrap.dedent("""\
            scryfall_id,nonfoil,foil
            69d20d28-76e9-4e6e-95c3-f88c51dfabfd,5,7
            """))
    import_path2.write_text(
        textwrap.dedent("""\
            scryfall_id,nonfoil,foil
            dd88131a-2811-4a1f-bb9a-c82e12c1493b,19,23
            """))

    args = ap.Namespace(collection=coll_path,
                        imports=[import_path1, import_path2],
                        dialect={})
    ssm.merge_cmd(args, oracle)

    assert set(work_path.iterdir()) == {
        coll_path,
        import_path1,
        import_path2,
        expected_backup_path,
    }
    assert coll_path.read_text() == textwrap.dedent("""\
        set,name,collector_number,scryfall_id,nonfoil,foil
        PMBS,Black Sun's Zenith,39,dd88131a-2811-4a1f-bb9a-c82e12c1493b,19,23
        MMA,Thallid,167,69d20d28-76e9-4e6e-95c3-f88c51dfabfd,6,10
        """)
    assert import_path1.read_text() == textwrap.dedent("""\
        scryfall_id,nonfoil,foil
        69d20d28-76e9-4e6e-95c3-f88c51dfabfd,5,7
        """)
    assert import_path2.read_text() == textwrap.dedent("""\
        scryfall_id,nonfoil,foil
        dd88131a-2811-4a1f-bb9a-c82e12c1493b,19,23
        """)
    assert expected_backup_path.read_text() == textwrap.dedent("""\
        scryfall_id,nonfoil,foil
        69d20d28-76e9-4e6e-95c3-f88c51dfabfd,1,3
        """)