from unittest import TestCase
from searchengine.parser.document import _read_document_id, _build_cacm_documents, _build_cacm_document, ReachedEndOfFile
from io import StringIO


class TestProcess(TestCase):

    def test_read_doc_id(self):
        text = StringIO(".I 42\n.T\ntata\n")
        self.assertEqual(42, _read_document_id(text))

    def test_read_doc(self):
        text = StringIO(".I 25\n.T\ntata\n.K\ntoto\n")
        doc = None
        try:
            doc = _build_cacm_document(text)
        except ReachedEndOfFile:
            pass
        self.assertEqual(25, doc.doc_id)
        self.assertEqual("tata\n", doc.title)
        self.assertEqual("toto\n", doc.keywords)

    def test_read_several_docs(self):
        text = StringIO(".I 25\n.T\ntata\n.K\ntoto\n.I 28\n.T\nyoyo\n")
        docs = _build_cacm_documents(text)
        self.assertEqual(2, len(docs))
        self.assertEqual("yoyo\n", docs[1].title)

@@ -1,12 +1,28 @@
+import unittest%0A
 from unittes
@@ -103,37 +103,33 @@
 id, 
-_build_cacm_documents, _build
+load_from_cacm, _get_next
 _cac
@@ -142,23 +142,66 @@
 ment
-, R
+%0Afrom s
 ea
+r
 che
-dEndOfF
+ngine.parser.document import load_from_cacm_f
 ile%0A
@@ -469,16 +469,31 @@
 %5Cntoto%5Cn
+.B%5Cnsome date%5Cn
 %22)%0A     
@@ -518,107 +518,46 @@
     
-try:%0A            doc = _build_cacm_document(text)%0A        except ReachedEndOfFile:%0A            pass
+_, doc = _get_next_cacm_document(text)
 %0A   
@@ -781,16 +781,35 @@
 ntoto%5Cn.
+B some date here%5Cn.
 I 28%5Cn.T
@@ -838,35 +838,34 @@
 s = 
-_build_cacm_documents
+list(load_from_cacm
 (text)
+)
 %0A   
@@ -942,16 +942,241 @@
  docs%5B1%5D.title)%0A
+%0A    @unittest.skip(%22Skipping this test until the resource file is distributed%22)%0A    def test_load_from_file(self):%0A        docs = load_from_cacm_file(%22./resources/cacm.all%22)%0A        self.assertEqual(3204, (len(list(docs))))%0A

Update tests.