import sys
import subprocess

import pytest


from multisieve_coreference.resolve_coreference import process_coreference


def test_main_example(example_naf_file, temp_file, example_naf_output):
    with open(example_naf_file) as fd, open(temp_file, 'w') as out:
        subprocess.check_call(
            [sys.executable, '-m', 'multisieve_coreference'],
            stdin=fd,
            stdout=out
        )
    from KafNafParserPy import KafNafParser
    with open(temp_file) as out, open(example_naf_output) as correct:
        assert KafNafParser(out).coreference_layer is not None
        out.seek(0)
        assert out.read() == correct.read()


def test_example_without_fill(example_naf_object, caplog):
    caplog.set_level('DEBUG', 'multisieve_coreference.dump')
    out = process_coreference(example_naf_object, fill_gaps=False)
    assert out.coreference_layer is not None


@pytest.mark.slow
def test_main_sonar1_without_fill(sonar_naf_object1, caplog):
    caplog.set_level('DEBUG', 'multisieve_coreference.dump')
    out = process_coreference(sonar_naf_object1, fill_gaps=False)
    assert out.coreference_layer is not None


def test_main_sonar2_without_fill(sonar_naf_object2, caplog):
    caplog.set_level('DEBUG', 'multisieve_coreference.dump')
    out = process_coreference(sonar_naf_object2, fill_gaps=False)
    assert out.coreference_layer is not None


@pytest.mark.slow
def test_main_sonar3_without_fill(sonar_naf_object3, caplog):
    caplog.set_level('DEBUG', 'multisieve_coreference.dump')
    out = process_coreference(sonar_naf_object3, fill_gaps=False)
    assert out.coreference_layer is not None


def test_example_with_fill(example_naf_object, caplog):
    caplog.set_level('DEBUG', 'multisieve_coreference.dump')
    out = process_coreference(example_naf_object, fill_gaps=True)
    assert out.coreference_layer is not None


@pytest.mark.slow
def test_main_sonar1_with_fill(sonar_naf_object1, caplog):
    caplog.set_level('DEBUG', 'multisieve_coreference.dump')
    out = process_coreference(sonar_naf_object1, fill_gaps=True)
    assert out.coreference_layer is not None


def test_main_sonar2_with_fill(sonar_naf_object2, caplog):
    caplog.set_level('DEBUG', 'multisieve_coreference.dump')
    out = process_coreference(sonar_naf_object2, fill_gaps=True)
    assert out.coreference_layer is not None


@pytest.mark.slow
def test_main_sonar3_with_fill(sonar_naf_object3, caplog):
    caplog.set_level('DEBUG', 'multisieve_coreference.dump')
    out = process_coreference(sonar_naf_object3, fill_gaps=True)
    assert out.coreference_layer is not None

@@ -762,38 +762,32 @@
 rence.dump')%0A   
- out =
  process_corefer
@@ -831,34 +831,49 @@
 lse)%0A    assert 
-ou
+example_naf_objec
 t.coreference_la
@@ -1026,38 +1026,32 @@
 rence.dump')%0A   
- out =
  process_corefer
@@ -1094,35 +1094,49 @@
 lse)%0A    assert 
-out
+sonar_naf_object1
 .coreference_lay
@@ -1270,38 +1270,32 @@
 rence.dump')%0A   
- out =
  process_corefer
@@ -1338,35 +1338,49 @@
 lse)%0A    assert 
-out
+sonar_naf_object2
 .coreference_lay
@@ -1532,38 +1532,32 @@
 rence.dump')%0A   
- out =
  process_corefer
@@ -1600,35 +1600,49 @@
 lse)%0A    assert 
-out
+sonar_naf_object3
 .coreference_lay
@@ -1770,38 +1770,32 @@
 rence.dump')%0A   
- out =
  process_corefer
@@ -1838,34 +1838,49 @@
 rue)%0A    assert 
-ou
+example_naf_objec
 t.coreference_la
@@ -2030,38 +2030,32 @@
 rence.dump')%0A   
- out =
  process_corefer
@@ -2097,35 +2097,49 @@
 rue)%0A    assert 
-out
+sonar_naf_object1
 .coreference_lay
@@ -2270,38 +2270,32 @@
 rence.dump')%0A   
- out =
  process_corefer
@@ -2337,35 +2337,49 @@
 rue)%0A    assert 
-out
+sonar_naf_object2
 .coreference_lay
@@ -2540,14 +2540,8 @@
 %0A   
- out =
  pro
@@ -2603,19 +2603,33 @@
  assert 
-out
+sonar_naf_object3
 .corefer

Fix most failing tests