File size: 1,006 Bytes
fb4c8c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Test radio_embed_p."""
# pylint: disable=broad-except, invalid-name
from pathlib import Path

import joblib
import numpy as np

from radio_embed_p import __version__, radio_embed_p
from radio_embed_p.radio_embed_p import radio_embed


def test_version():
    """Test version."""
    assert __version__[:3] == "0.1"


def test_sanity():
    """Check sanity."""
    try:
        assert not radio_embed_p()
    except Exception:
        assert True


def test_ff_en():
    """Test ff-en.txt."""
    # __file__ = "tests/test_radio_embed_p.py"

    # fpath = Path(__file__).parent / "ff-en.lzma"
    # r = joblib.load(fpath)

    fpath = Path(__file__).parent / "fangfang-en.txt"
    lst = [
        elm.strip() for elm in Path(fpath).read_text("utf8").splitlines() if elm.strip()
    ]
    text = "\n".join(lst[:100])

    r = radio_embed(text)

    # import os
    # os.environ["TOKENIZERS_PARALLELISM"] = "false"
    r1 = radio_embed_p(text)

    assert np.allclose(np.array(r), np.array(r1), atol=1e-07)