# coding: utf8
from __future__ import unicode_literals

import pytest

from ...attrs import ENT_IOB, ENT_TYPE
from ...tokens import Doc
from ..util import get_doc


@pytest.mark.xfail
def test_issue3012(en_vocab):
    words = ["This", "is", "10", "%", "."]
    tags = ["DT", "VBZ", "CD", "NN", "."]
    pos = ["DET", "VERB", "NUM", "NOUN", "PUNCT"]
    ents = [(2, 4, "PERCENT")]
    doc = get_doc(en_vocab, words=words, tags=tags, pos=pos, ents=ents)

    expected = ("10", "NUM", "CD", "PERCENT")
    assert (doc[2].text, doc[2].pos_, doc[2].tag_, doc[2].ent_type_) == expected

    # now removing '10%' entity
    assert len(doc.ents) == 1
    header = [ENT_IOB, ENT_TYPE]
    ent_array = doc.to_array(header)
    ent = doc.ents[0]
    for idx in range(ent.start, ent.end):
        ent_array[idx, 0] = 0
        ent_array[idx, 1] = 0
    doc.from_array(header, ent_array)
    assert len(doc.ents) == 0

    assert (doc[2].text, doc[2].pos_, doc[2].tag_, doc[2].ent_type_) == expected

    # serializing then deserializing
    doc_bytes = doc.to_bytes()
    doc2 = Doc(en_vocab).from_bytes(doc_bytes)
    assert len(doc2.ents) == 0

    assert (doc[2].text, doc[2].pos_, doc[2].tag_, doc[2].ent_type_) == expected

@@ -162,27 +162,8 @@
 c%0A%0A%0A
-@pytest.mark.xfail%0A
 def 
@@ -188,16 +188,132 @@
 vocab):%0A
+    %22%22%22Test that the is_tagged attribute doesn't get overwritten when we from_array%0A    without tag information.%22%22%22%0A
     word
@@ -541,16 +541,41 @@
 ts=ents)
+%0A    assert doc.is_tagged
 %0A%0A    ex
@@ -700,70 +700,8 @@
 ed%0A%0A
-    # now removing '10%25' entity%0A    assert len(doc.ents) == 1%0A
     
@@ -770,132 +770,8 @@
 er)%0A
-    ent = doc.ents%5B0%5D%0A    for idx in range(ent.start, ent.end):%0A        ent_array%5Bidx, 0%5D = 0%0A        ent_array%5Bidx, 1%5D = 0%0A
     
@@ -807,38 +807,8 @@
 ray)
-%0A    assert len(doc.ents) == 0
 %0A%0A  
@@ -955,16 +955,16 @@
 bytes()%0A
+
     doc2
@@ -1006,40 +1006,8 @@
 es)%0A
-    assert len(doc2.ents) == 0%0A%0A
     

Update test for #3012