Skip to content

Commit

Permalink
Detect when a fasttext executable is available in PATH (piskvorky#3264)
Browse files Browse the repository at this point in the history
Also check that fasttext exists in FT_HOME and is executable.

This is useful when using a distro like Debian that
has a package of fasttext available to install.

Co-authored-by: Michael Penkov <[email protected]>
  • Loading branch information
pabs3 and mpenkov committed Feb 26, 2022
1 parent 6fc9e38 commit d6620df
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions gensim/test/test_fasttext.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import unittest
import os
import shutil
import subprocess
import struct
import sys
Expand Down Expand Up @@ -44,7 +45,8 @@
BUCKET = 10000

FT_HOME = os.environ.get("FT_HOME")
FT_CMD = os.path.join(FT_HOME, "fasttext") if FT_HOME else None
FT_CMD = shutil.which("fasttext", path=FT_HOME) or \
shutil.which("fasttext")


new_sentences = [
Expand Down Expand Up @@ -1661,7 +1663,7 @@ def _save_test_model(out_base_fname, model_params):
subprocess.check_call(cmd)


@unittest.skipIf(not FT_HOME, "FT_HOME env variable not set, skipping test")
@unittest.skipIf(not FT_CMD, "fasttext not in FT_HOME or PATH, skipping test")
class SaveFacebookByteIdentityTest(unittest.TestCase):
"""
This class containts tests that check the following scenario:
Expand Down Expand Up @@ -1708,7 +1710,7 @@ def line_to_array(line):
return np.array([line_to_array(line) for line in out.splitlines()], dtype=np.float32)


@unittest.skipIf(not os.environ.get("FT_HOME", None), "FT_HOME env variable not set, skipping test")
@unittest.skipIf(not FT_CMD, "fasttext not in FT_HOME or PATH, skipping test")
class SaveFacebookFormatReadingTest(unittest.TestCase):
"""
This class containts tests that check the following scenario:
Expand Down

0 comments on commit d6620df

Please sign in to comment.