processors.tests.test_serialization   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 28
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A SerializationTests.test_sentence_load_from_json() 0 7 2
A SerializationTests.test_mention_load_from_json() 0 9 2
A SerializationTests.test_doc_load_from_json() 0 7 2
1
# -*- coding: utf-8 -*-
2
3
import unittest
4
from processors import *
5
import os
6
7
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
8
9
class SerializationTests(unittest.TestCase):
10
11
    def test_doc_load_from_json(self):
12
        "Document.load_from_JSON should produce a Document from serialized_doc.json"
13
        json_file = os.path.join(__location__, "serialized_doc.json")
14
        print(json_file)
15
        with open(json_file, "r") as jf:
16
            doc = Document.load_from_JSON(json.load(jf))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable Document does not seem to be defined.
Loading history...
17
        self.assertTrue(isinstance(doc, Document), "Document.load_from_JSON did not produce a Document from {}".format(json_file))
18
19
    def test_sentence_load_from_json(self):
20
        "Sentence.load_from_JSON should produce a Sentence from serialized_sentence.json"
21
        json_file = os.path.join(__location__, "serialized_sentence.json")
22
        print(json_file)
23
        with open(json_file, "r") as jf:
24
            s = Sentence.load_from_JSON(json.load(jf))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable Sentence does not seem to be defined.
Loading history...
25
        self.assertTrue(isinstance(s, Sentence), "Sentence.load_from_JSON did not produce a Sentence from {}".format(json_file))
26
27
    def test_mention_load_from_json(self):
28
        "JSONSerializer.load_from_JSON should produce a Mention from serialized_mention.json"
29
        json_file = os.path.join(__location__, "serialized_mention.json")
30
        print(json_file)
31
        with open(json_file, "r") as jf:
32
            mentions = JSONSerializer.mentions_from_JSON(json.load(jf))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable JSONSerializer does not seem to be defined.
Loading history...
33
        self.assertTrue(len(mentions) == 1, "More than one mention found for text.")
34
        m = mentions[0]
35
        self.assertTrue(isinstance(m, Mention), "JSONSerializer.load_from_JSON did not produce a Mention from {}".format(json_file))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable Mention does not seem to be defined.
Loading history...
36
37
if __name__ == "__main__":
38
    unittest.main()
39