from django.test import SimpleTestCase

from export.export import (
    split_syntax, separate_phrasetype, separate_syntax,
    merge_primary_and_syntax)


class TestSplitSyntax(SimpleTestCase):
    def test_normal_split(self):
        self.assertEqual(split_syntax('Agent V Patient'), ['Agent', 'V', 'Patient'])
        self.assertEqual(split_syntax('Agent V   Patient'), ['Agent', 'V', 'Patient'])
        self.assertEqual(split_syntax(
            'Agent V {{+loc}} Location'),
            ['Agent', 'V', '{{+loc}}', 'Location'])

    def test_preposition_list(self):
        self.assertEqual(split_syntax(
            'Agent V {à dans verbs} Location'),
            ['Agent', 'V', '{à dans verbs}', 'Location'])
        self.assertEqual(split_syntax('Agent V {à} Location'), ['Agent', 'V', '{à}', 'Location'])


class TestSeparatePhraseType(SimpleTestCase):
    def test_simple_phrase(self):
        self.assertEqual(separate_phrasetype('NP'), ('NP', None))

    def test_phrase_with_role(self):
        self.assertEqual(separate_phrasetype('NP.Agent'), ('NP', 'Agent'))
        self.assertEqual(separate_phrasetype('NP.agent'), ('NP', 'Agent'))

    def test_phrase_with_alternation(self):
        # Get rid of -Middle - doesn't seem useful and should be in the
        # secondary attribute
        self.assertEqual(separate_phrasetype('NP-Middle'), ('NP', None))

    def test_something_else(self):
        self.assertEqual(separate_phrasetype('V'), ('V', None))
        self.assertEqual(separate_phrasetype('se'), ('se', None))
        self.assertEqual(separate_phrasetype('abcd.ert'), ('abcd.ert', None))


class TestSeparateSyntax(SimpleTestCase):
    def test_no_role(self):
        self.assertEqual(separate_syntax('NP'), ('NP', None))
        self.assertEqual(separate_syntax('V'), ('V', None))
        self.assertEqual(separate_syntax('V<+neutre>'), ('V', '<+neutre>'))

    def test_simple_role(self):
        self.assertEqual(separate_syntax('Agent'), ('Agent', None))

    def test_modified_role(self):
        self.assertEqual(separate_syntax('Instrument<+Plural>'), ('Instrument', '<+Plural>'))


class TestFullMerge(SimpleTestCase):
    def test_simple_sentence(self):
        self.assertEqual(
            merge_primary_and_syntax('NP V NP', 'Agent V Patient'),
            [{'role': 'Agent', 'type': 'NP'},
                {'type': 'V'},
                {'role': 'Patient', 'type': 'NP'}])

    def test_neutral_verb(self):
        self.assertEqual(
            merge_primary_and_syntax('NP V NP', 'Agent V<+neutre> Patient'),
            [{'role': 'Agent', 'type': 'NP'},
                {'attribute': 'neutre', 'type': 'V'},
                {'role': 'Patient', 'type': 'NP'}])

    def test_adverb_as_role(self):
        self.assertEqual(
            merge_primary_and_syntax('NP V ADV-Middle', 'Patient V ADV'),
            [{'role': 'Patient', 'type': 'NP'},
                {'type': 'V'},
                {'type': 'ADV'}])

    def test_adj_as_role(self):
        self.assertEqual(
            merge_primary_and_syntax('NP V NP Adj', 'Pivot V Theme Adj'),
            [{'type': 'NP', 'role': 'Pivot'},
             {'type': 'V'},
             {'type': 'NP', 'role': 'Theme'},
             {'type': 'Adj'}])

    def test_que(self):
        self.assertEqual(
            merge_primary_and_syntax('NP V que S', 'Agent V Theme<+que_comp>'),
            [{'role': 'Agent', 'type': 'NP'},
             {'type': 'V'},
             {'type': 'S', 'role': 'Theme', 'introduced_by': 'que', 'restr': 'comp'}])

    def test_de(self):
        self.assertEqual(
            merge_primary_and_syntax('NP V de V-inf', 'Pivot V Theme<+de_Vinf>'),
            [{'type': 'NP', 'role': 'Pivot'},
             {'type': 'V'},
             {'type': 'V-inf', 'role': 'Theme', 'introduced_by': 'de', 'restr': 'Vinf'}])

@@ -1,12 +1,24 @@
+import sys%0A%0A
 from django.
@@ -2277,35 +2277,54 @@
 Agent V Patient'
+, output=sys.stderr
 ),%0A
-
             %5B%7B'r
@@ -2570,16 +2570,35 @@
 Patient'
+, output=sys.stderr
 ),%0A     
@@ -2877,16 +2877,35 @@
 t V ADV'
+, output=sys.stderr
 ),%0A     
@@ -3142,16 +3142,35 @@
 eme Adj'
+, output=sys.stderr
 ),%0A     
@@ -3443,16 +3443,35 @@
 e_comp%3E'
+, output=sys.stderr
 ),%0A     
@@ -3668,32 +3668,32 @@
 lf.assertEqual(%0A
-
             merg
@@ -3755,16 +3755,35 @@
 e_Vinf%3E'
+, output=sys.stderr
 ),%0A     

Fix tests by using the output parameter