langdetect icon indicating copy to clipboard operation
langdetect copied to clipboard

Profile format error

Open ziky90 opened this issue 9 years ago • 1 comments

Hi,

I am currently experiencing the following problem:

LangDetectException: Profile format error in "/Users/jan/.virtualenvs/literature_pipeline/lib/python2.7/site-packages/langdetect/profiles/af"

This seems to me quiet related to already closed https://github.com/Mimino666/langdetect/issues/2

Moreover playing with this it seems to me that this problem appears only when I use the library in combination with mock.

In other words: When I do:

ipython
from langdetect import detect_langs
detect_langs("this is a sample english text")

Then result is [en:0.999997436115]

But when I call the code from my tests (using python setup.py test), then I am getting this Exception.

My test code looks like this:

with mock.patch("io.open", mock.mock_open(read_data='{"abstract":"This is a sample english text"}')) as mock_file:
    with mock.patch("__builtin__.open") as file_write:
        language = detect_langs("This is a sample english text")

I am using virtualenvwrapper, Python 2.7.10 and langdetect==1.0.5

Do you have any idea what can be possibly wrong?

ziky90 avatar Jan 14 '16 12:01 ziky90

It seems that is problem is that mock is mocking all the files opening and detect_tags internally opens files as well.

ziky90 avatar Jan 14 '16 15:01 ziky90