def test_tesaurus_buat_url_dengan_kelas(): te = Tesaurus() te.kata = "mock" te.kelas_kata = "adjektiva" laman = te._buat_url() expect = f"{te.HOST}/mock/adjektiva" assert laman == expect
def test_simulasi_404_error(): te = Tesaurus() te.kata = "mock" sample = SimpleNamespace(status_code=404, text="") with pytest.raises(TidakDitemukan) as excinfo: te._cek_galat(sample) assert "Tidak dapat menemukan kata mock pada semua kelas kata" in str( excinfo)
def test_simulasi_xxx_error(): te = Tesaurus() te.kata = "mock" sample = SimpleNamespace(status_code=500, text="") with pytest.raises(TerjadiKesalahan) as excinfo: te._cek_galat(sample) assert "Terjadi kesalahan ketika berkomunikasi dengan website Tesaurus" in str( excinfo)
def test_tesaurus_sesi_close(): te = Tesaurus() te.tutup() full_closed = True for adapter in te.sesi.adapters.values(): if len(adapter.poolmanager.pools) > 0: full_closed = False assert full_closed is True
def test_tesaurus_buat_url_kelas_tidak_diketahui(): te = Tesaurus() te.kata = "mock" te.kelas_kata = "adjective" with pytest.raises(KelasKataTidakDiketahui) as excinfo: te._buat_url() assert "Kelas kata adjective tidak diketahui." in str(excinfo.value)
def test_tesaurus_buat_url(): te = Tesaurus() te.kata = "mock" laman = te._buat_url() expect = f"{te.HOST}/mock" assert laman == expect
def test_tesaurus_sesi(): sample = requests.Session() mock_header = {"Sample-Header": "Mocked"} sample.headers.update(mock_header) te = Tesaurus(sample) assert te.sesi.headers.get("Sample-Header") == "Mocked"
def test_simulasi_str_tanpa_entri(): te = Tesaurus() te.kata = "makan" assert "makan\nTidak ada hasil." == str(te)
def test_simulasi_terkait_error_silent_2(): te = Tesaurus() te.kata = "makan" te._buat_terkait(SAMPLE_HTML_2) assert len(te.terkait) == 1
def test_simulasi_terkait_error_silent(): te = Tesaurus() te.kata = "makan" te._buat_terkait(SAMPLE_HTML_1) assert te.terkait == []
def test_simulasi_terkait_kosong(): te = Tesaurus() te._buat_terkait("<div>mock</div>") assert te.terkait == []
def test_tesaurus_terkait(): te = Tesaurus() assert te.terkait == []
def test_tesaurus_entri(): te = Tesaurus() assert te.entri == []