Organize test suite into classes

Offen
#257 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Refactoring
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
testing

Rechercherichtung

Beginne mit der Testdatei, die den Abschnitt pin_write für pins.board.BaseBoard enthält, und identifiziere dann die anderen durch Kommentare getrennten Testabschnitte, jeweils eine Datei nach der anderen. Wandle diese Abschnitte in verschachtelte Testklassen um und kürze die Methodennamen, wobei die vorhandenen Assertions und Fixtures erhalten bleiben. Führe die betroffene pytest-Datei nach jeder Umwandlung aus und bestätige, dass die vollständige Testsuite weiterhin erfolgreich durchläuft.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

testing

Currently tests are organized into modules and then separated into sections using comment rules e.g.

# pin_download ===================================================================

This can make it hard to navigate the test suite and also results in longer test names: the test names include both the category information and the specifics of the test.

Pytest allows you to organize tests into classes. Besides adding some clarity to the test organization, this also allows the user to have more fine-grained control about which tests run.

So I would propose changing the following:

# pin_write ===================================================================

def test_board_pin_write_default_title(board):

    df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
    meta = board.pin_write(df, "df_csv", title=None, type="csv")
    assert meta.title == "df_csv: a pinned 3 x 2 DataFrame"


def test_board_pin_write_prepare_pin(board, tmp_dir2):

    df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})

    meta = board.prepare_pin_version(
        str(tmp_dir2), df, "df_csv", title=None, type="csv"
    )
    assert meta.file == "df_csv.csv"
    assert (tmp_dir2 / "data.txt").exists()
    assert (tmp_dir2 / "df_csv.csv").exists()
    assert not (tmp_dir2 / "df_csv.csv").is_dir()


def test_board_pin_write_roundtrip(board):

    df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})

    assert not board.pin_exists("df_csv")

    board.pin_write(df, "df_csv", type="csv")

    assert board.pin_exists("df_csv")

    loaded_df = board.pin_read("df_csv")
    assert loaded_df.equals(df)


def test_board_pin_write_type_not_specified_error(board):
    class C:
        pass

    with pytest.raises(NotImplementedError):
        board.pin_write(C(), "cool_pin")

To this:

class TestBoard:
    ... # All the other sets of tests on pins.board.BaseBoard methods...
    class TestPinWrite:
        def test_default_title(self, board):
        
            df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
            meta = board.pin_write(df, "df_csv", title=None, type="csv")
            assert meta.title == "df_csv: a pinned 3 x 2 DataFrame"
        
        
        def test_prepare_pin(self, board, tmp_dir2):
        
            df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
        
            meta = board.prepare_pin_version(
                str(tmp_dir2), df, "df_csv", title=None, type="csv"
            )
            assert meta.file == "df_csv.csv"
            assert (tmp_dir2 / "data.txt").exists()
            assert (tmp_dir2 / "df_csv.csv").exists()
            assert not (tmp_dir2 / "df_csv.csv").is_dir()
        
        
        def test_roundtrip(self, board):
        
            df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
        
            assert not board.pin_exists("df_csv")
        
            board.pin_write(df, "df_csv", type="csv")
        
            assert board.pin_exists("df_csv")
        
            loaded_df = board.pin_read("df_csv")
            assert loaded_df.equals(df)
        
        
        def test_type_not_specified_error(self, board):
            class C:
                pass
        
            with pytest.raises(NotImplementedError):
                board.pin_write(C(), "cool_pin")
        
        ... # etc.

My plan for making this change would be one test file at a time.

Vorherrschende Sprache
Python
Sterne
59
Forks
11
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus rstudio/pins-python

Alle Issues in rstudio/pins-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.