From 071a4d4d55879802b5a4c6d4bff8c7c5bb401178 Mon Sep 17 00:00:00 2001 From: Drokonor Date: Wed, 24 Oct 2018 13:59:19 +0300 Subject: [PATCH 1/3] test of models.py --- link_analysis/models.py | 2 +- link_analysis/testmodels.py | 1014 +++++++++++++++++++++++++++++++++++ link_analysis/testrough.py | 62 +++ 3 files changed, 1077 insertions(+), 1 deletion(-) create mode 100644 link_analysis/testmodels.py create mode 100644 link_analysis/testrough.py diff --git a/link_analysis/models.py b/link_analysis/models.py index 2b5cd4e..7a9d424 100644 --- a/link_analysis/models.py +++ b/link_analysis/models.py @@ -99,7 +99,7 @@ class Header(DocumentHeader): def __init__(self, docID: str, docType: str, title: str, releaseDate: datetime.date, textSourceUrl: str, - textLocation: Optional[str]) -> None: + textLocation: Optional[str]=None) -> None: """ Constructor which uses superclass constructor passing it an arg docID. diff --git a/link_analysis/testmodels.py b/link_analysis/testmodels.py new file mode 100644 index 0000000..37c3007 --- /dev/null +++ b/link_analysis/testmodels.py @@ -0,0 +1,1014 @@ +import datetime +import collections +import unittest +from models import DocumentHeader, Header, DuplicateHeader, Link, RoughLink +from models import CleanLink, HeadersFilter, GraphNodesFilter, GraphEdgesFilter +from models import LinkGraph + + +class DocumentHeaderTestCase(unittest.TestCase): + def setUp(self): + self.header1 = DocumentHeader(r'КСРФ/31-П/2018') + self.header2 = DocumentHeader(r'КСРФ/31-П/2018') + self.header3 = DocumentHeader(r'КСРФ/30-П/2018') + + def testCreate1(self): + try: + self.header4 = DocumentHeader(r'КСРФ/31-П/2018') + TestStatus = True + except TypeError: + TestStatus = False + self.assertTrue(TestStatus) + + def testCreate2(self): + try: + self.header4 = DocumentHeader(True) + TestStatus = True + except TypeError: + TestStatus = False + self.assertFalse(TestStatus) + + def testEq1(self): + TestStatus = self.header1 == self.header2 + self.assertTrue(TestStatus) + + def testEq2(self): + TestStatus = self.header1 == self.header3 + self.assertFalse(TestStatus) + + def testNe1(self): + TestStatus = self.header1 != self.header2 + self.assertFalse(TestStatus) + + def testNe2(self): + TestStatus = self.header1 != self.header3 + self.assertTrue(TestStatus) + + def testHash1(self): + HeaderList = [] + i = 0 + while i < 100: + i += 1 + HeaderList.append(DocumentHeader(r'КСРФ/32-П/2018')) + TestStatus = True + for header in HeaderList: + if header.__hash__ != HeaderList[0].__hash__: + TestStatus = False + self.assertTrue(TestStatus) + + def testHash2(self): + HeaderList = [] + i = 0 + while i < 100: + i += 1 + HeaderList.append(DocumentHeader(r'КСРФ/'+str(i)+r'-П/2018')) + HeaderList = [header.__hash__() for header in HeaderList] + TestStatus = True + for header in HeaderList: + if HeaderList.count(header) != 1: + TestStatus = False + self.assertTrue(TestStatus) + + +class HeaderTestCase(unittest.TestCase): + def setUp(self): + self.header1 = Header( + r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf') + self.header2 = Header( + r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf') + self.header3 = Header( + r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') + + def testCreate1(self): + try: + self.header4 = Header( + r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') + TestStatus = True + except TypeError: + TestStatus = False + self.assertTrue(TestStatus) + + def testCreate2(self): + try: + self.header4 = Header( + r'КСРФ/30-О/2018', 12, False, + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') + TestStatus = True + except TypeError: + TestStatus = False + self.assertFalse(TestStatus) + + def testEq1(self): + TestStatus = self.header1 == self.header2 + self.assertTrue(TestStatus) + + def testEq2(self): + TestStatus = self.header1 == self.header3 + self.assertFalse(TestStatus) + + def testNe1(self): + TestStatus = self.header1 != self.header2 + self.assertFalse(TestStatus) + + def testNe2(self): + TestStatus = self.header1 != self.header3 + self.assertTrue(TestStatus) + + def testHash1(self): + HeaderList = [] + i = 0 + while i < 100: + i += 1 + HeaderList.append( + Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf')) + TestStatus = True + for header in HeaderList: + if header.__hash__ != HeaderList[0].__hash__: + TestStatus = False + self.assertTrue(TestStatus) + + def testHash2(self): + HeaderList = [] + i = 0 + while i < 100: + i += 1 + HeaderList.append( + Header(r'КСРФ/'+str(i)+r'-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf')) + HeaderList = [header.__hash__() for header in HeaderList] + TestStatus = True + for header in HeaderList: + if HeaderList.count(header) != 1: + TestStatus = False + self.assertTrue(TestStatus) + + +class DuplicateHeaderTestCase(unittest.TestCase): + def setUp(self): + self.header1 = DuplicateHeader( + r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf') + self.header2 = DuplicateHeader( + r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf') + self.header3 = DuplicateHeader( + r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') + + def testCreate1(self): + try: + self.header4 = DuplicateHeader( + r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') + TestStatus = True + except TypeError: + TestStatus = False + self.assertTrue(TestStatus) + + def testCreate2(self): + try: + self.header4 = DuplicateHeader( + r'КСРФ/30-О/2018', r'КСРФ/О', 1488, + 'datetime.date(2018, 9, 27)', + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') + TestStatus = True + except TypeError: + TestStatus = False + self.assertFalse(TestStatus) + + def testEq1(self): + TestStatus = self.header1 == self.header2 + self.assertTrue(TestStatus) + + def testEq2(self): + TestStatus = self.header1 == self.header3 + self.assertFalse(TestStatus) + + def testNe1(self): + TestStatus = self.header1 != self.header2 + self.assertFalse(TestStatus) + + def testNe2(self): + TestStatus = self.header1 != self.header3 + self.assertTrue(TestStatus) + + def testHash1(self): + HeaderList = [] + i = 0 + while i < 100: + i += 1 + HeaderList.append( + DuplicateHeader(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/357646.pdf')) + TestStatus = True + for header in HeaderList: + if header.__hash__ != HeaderList[0].__hash__: + TestStatus = False + self.assertTrue(TestStatus) + + def testHash2(self): + HeaderList = [] + i = 0 + while i < 100: + i += 1 + HeaderList.append( + DuplicateHeader(r'КСРФ/'+str(i)+r'-П/2018', + r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/357646.pdf')) + HeaderList = [header.__hash__() for header in HeaderList] + TestStatus = True + for header in HeaderList: + if HeaderList.count(header) != 1: + TestStatus = False + self.assertTrue(TestStatus) + + +class LinkTestCase(unittest.TestCase): + def setUp(self): + self.link1 = Link( + Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf')) + self.link2 = Link( + Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf')) + self.link3 = Link( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf')) + + def testCreate1(self): + try: + self.link4 = Link( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision' + f'/KSRFDecision357727.pdf')) + TestStatus = True + except TypeError: + TestStatus = False + self.assertTrue(TestStatus) + + def testCreate2(self): + try: + self.link4 = Link( + Header(True, r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + 322)) + TestStatus = True + except TypeError: + TestStatus = False + self.assertFalse(TestStatus) + + def testEq1(self): + TestStatus = self.link1 == self.link2 + self.assertTrue(TestStatus) + + def testEq2(self): + TestStatus = self.link1 == self.link3 + self.assertFalse(TestStatus) + + def testNe1(self): + TestStatus = self.link1 != self.link2 + self.assertFalse(TestStatus) + + def testNe2(self): + TestStatus = self.link1 != self.link3 + self.assertTrue(TestStatus) + + def testHash1(self): + LinkList = [] + i = 0 + while i < 100: + i += 1 + LinkList.append( + Link(Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/357646.pdf'))) + TestStatus = True + for link in LinkList: + if link.__hash__ != LinkList[0].__hash__: + TestStatus = False + self.assertTrue(TestStatus) + + def testHash2(self): + LinkList = [] + i = 0 + while i < 100: + i += 1 + LinkList.append( + Link(Header(r'КСРФ/'+str(i)+r'-П/2018', + r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/357646.pdf'))) + LinkList = [link.__hash__() for link in LinkList] + TestStatus = True + for link in LinkList: + if LinkList.count(link) != 1: + TestStatus = False + self.assertTrue(TestStatus) + + +class RoughLinkTestCase(unittest.TestCase): + def setUp(self): + self.link1 = RoughLink( + Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), + 'постановление', 'от 1 мая 2018 года № 31-П', 31) + self.link2 = RoughLink( + Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), + 'постановление', 'от 1 мая 2018 года № 31-П', 31) + self.link3 = RoughLink( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), + 'определение', 'от 2 мая 2018 года № 30-О', 30) + + def testCreate1(self): + try: + self.link4 = RoughLink( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), + 'определение', 'от 2 мая 2018 года № 30-О', 30) + TestStatus = True + except TypeError: + TestStatus = False + self.assertTrue(TestStatus) + + def testCreate2(self): + try: + self.link4 = RoughLink( + 'Header', + 'определение', 'от 2 мая 2018 года № 30-О', 30) + TestStatus = True + except TypeError: + TestStatus = False + self.assertFalse(TestStatus) + + def testEq1(self): + TestStatus = self.link1 == self.link2 + self.assertTrue(TestStatus) + + def testEq2(self): + TestStatus = self.link1 == self.link3 + self.assertFalse(TestStatus) + + def testNe1(self): + TestStatus = self.link1 != self.link2 + self.assertFalse(TestStatus) + + def testNe2(self): + TestStatus = self.link1 != self.link3 + self.assertTrue(TestStatus) + + def testHash1(self): + LinkList = [] + i = 0 + while i < 100: + i += 1 + LinkList.append(RoughLink( + Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf'), + 'постановление', 'от 3 мая 2018 года № 32-П', 32)) + TestStatus = True + for link in LinkList: + if link.__hash__ != LinkList[0].__hash__: + TestStatus = False + self.assertTrue(TestStatus) + + def testHash2(self): + LinkList = [] + i = 0 + while i < 100: + i += 1 + LinkList.append(RoughLink( + Header(r'КСРФ/'+str(i)+r'-П/2018', + r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf'), + 'постановление', 'от 3 мая 2018 года № 32-П', 32)) + LinkList = [link.__hash__() for link in LinkList] + TestStatus = True + for link in LinkList: + if LinkList.count(link) != 1: + TestStatus = False + self.assertTrue(TestStatus) + + +class CleanLinkTestCase(unittest.TestCase): + def setUp(self): + self.link1 = CleanLink( + Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), + Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)'), + 31, (31, 'постановление')) + self.link2 = CleanLink( + Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), + Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)'), + 31, (31, 'постановление')) + self.link3 = CleanLink( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), + Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', + datetime.date(2018, 9, 28), + r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), + 30, (30, 'определение')) + + def testCreate1(self): + try: + self.link4 = CleanLink( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), + Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', + datetime.date(2018, 9, 28), + r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), + 30, (30, 'определение')) + TestStatus = True + except TypeError: + TestStatus = False + self.assertTrue(TestStatus) + + def testCreate2(self): + try: + self.link4 = CleanLink( + Header(r'КСРФ/30-О/2018', 228, 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), + Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', + 'datetime.date(2018, 9, 28)', + r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), + '30', (30, 'определение')) + TestStatus = True + except TypeError: + TestStatus = False + self.assertFalse(TestStatus) + + def testEq1(self): + TestStatus = self.link1 == self.link2 + self.assertTrue(TestStatus) + + def testEq2(self): + TestStatus = self.link1 == self.link3 + self.assertFalse(TestStatus) + + def testNe1(self): + TestStatus = self.link1 != self.link2 + self.assertFalse(TestStatus) + + def testNe2(self): + TestStatus = self.link1 != self.link3 + self.assertTrue(TestStatus) + + def testHash1(self): + LinkList = [] + i = 0 + while i < 100: + i += 1 + LinkList.append(CleanLink( + Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf'), + Header(r'КСРФ/33-П/2018', r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf'), + 32, (32, 'постановление'))) + TestStatus = True + for link in LinkList: + if link.__hash__ != LinkList[0].__hash__: + TestStatus = False + self.assertTrue(TestStatus) + + def testHash2(self): + LinkList = [] + i = 0 + while i < 100: + i += 1 + LinkList.append(CleanLink( + Header(r'КСРФ/'+str(i)+r'-П/2018', + r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf'), + Header(r'КСРФ/'+str(i+100)+r'-П/2018', + r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf'), + 32, (32, 'постановление'))) + LinkList = [link.__hash__() for link in LinkList] + TestStatus = True + for link in LinkList: + if LinkList.count(link) != 1: + TestStatus = False + self.assertTrue(TestStatus) + + +class HeadersFilterTestCase(unittest.TestCase): + def setUp(self): + self.header1 = HeadersFilter(r'КСРФ/П', datetime.date(2018, 10, 16), + datetime.date(2018, 10, 17)) + self.header2 = HeadersFilter(r'КСРФ/П', datetime.date(2018, 10, 16), + datetime.date(2018, 10, 17)) + self.header3 = HeadersFilter(r'КСРФ/О', datetime.date(2018, 9, 27), + datetime.date(2018, 9, 28)) + + def testCreate1(self): + try: + self.header4 = HeadersFilter(r'КСРФ/О', + datetime.date(2018, 9, 27), + datetime.date(2018, 9, 28)) + TestStatus = True + except TypeError: + TestStatus = False + self.assertTrue(TestStatus) + + def testCreate2(self): + try: + self.header4 = HeadersFilter(r'КСРФ/О', + True, + datetime.date(2018, 9, 28)) + TestStatus = True + except TypeError: + TestStatus = False + self.assertFalse(TestStatus) + + def testEq1(self): + TestStatus = self.header1 == self.header2 + self.assertTrue(TestStatus) + + def testEq2(self): + TestStatus = self.header1 == self.header3 + self.assertFalse(TestStatus) + + def testNe1(self): + TestStatus = self.header1 != self.header2 + self.assertFalse(TestStatus) + + def testNe2(self): + TestStatus = self.header1 != self.header3 + self.assertTrue(TestStatus) + + def testHash1(self): + HeaderList = [] + i = 0 + while i < 100: + i += 1 + HeaderList.append(HeadersFilter(r'КСРФ/П', + datetime.date(2018, 10, 16), + datetime.date(2018, 10, 17))) + TestStatus = True + for header in HeaderList: + if header.__hash__ != HeaderList[0].__hash__: + TestStatus = False + self.assertTrue(TestStatus) + + def testHash2(self): + HeaderList = [] + i = 0 + while i < 100: + i += 1 + HeaderList.append(HeadersFilter(r'КСРФ/П'+str(i), + datetime.date(i, 10, 16), + datetime.date(i, 10, 17))) + HeaderList = [header.__hash__() for header in HeaderList] + TestStatus = True + for header in HeaderList: + if HeaderList.count(header) != 1: + TestStatus = False + self.assertTrue(TestStatus) + + def testFilteredHeaders(self): + HeadersDict = {r'КСРФ/31-П/2018': Header( + r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf')} + TestStatus = True + self.header4 = HeadersFilter() + if self.header1.get_filtered_headers(HeadersDict) is None: + TestStatus = False + self.assertTrue(TestStatus) + + +class GraphNodesFilterTestCase(unittest.TestCase): + def setUp(self): + self.node1 = GraphNodesFilter(r'КСРФ/П', datetime.date(2018, 10, 16), + datetime.date(2018, 10, 17), + (0, 31), (32, 60)) + self.node2 = GraphNodesFilter(r'КСРФ/П', datetime.date(2018, 10, 16), + datetime.date(2018, 10, 17), + (0, 31), (32, 60)) + self.node3 = GraphNodesFilter(r'КСРФ/О', datetime.date(2018, 9, 27), + datetime.date(2018, 9, 28), + (0, 30), (31, 60)) + + def testCreate1(self): + try: + self.node4 = GraphNodesFilter(r'КСРФ/О', + datetime.date(2018, 9, 27), + datetime.date(2018, 9, 28), + (0, 30), (31, 60)) + TestStatus = True + except TypeError: + TestStatus = False + self.assertTrue(TestStatus) + + def testCreate2(self): + try: + self.node4 = GraphNodesFilter(r'КСРФ/О', + datetime.date(2018, 9, 27), + datetime.date(2018, 9, 28), + (0, 'lol'), ('proverka', 60)) + TestStatus = True + except TypeError: + TestStatus = False + self.assertFalse(TestStatus) + + def testEq1(self): + TestStatus = self.node1 == self.node2 + self.assertTrue(TestStatus) + + def testEq2(self): + TestStatus = self.node1 == self.node3 + self.assertFalse(TestStatus) + + def testNe1(self): + TestStatus = self.node1 != self.node2 + self.assertFalse(TestStatus) + + def testNe2(self): + TestStatus = self.node1 != self.node3 + self.assertTrue(TestStatus) + + def testHash1(self): + NodeList = [] + i = 0 + while i < 100: + i += 1 + NodeList.append(GraphNodesFilter(r'КСРФ/П', + datetime.date(2018, 10, 16), + datetime.date(2018, 10, 17), + (0, 32), (33, 60))) + TestStatus = True + for node in NodeList: + if node.__hash__ != NodeList[0].__hash__: + TestStatus = False + self.assertTrue(TestStatus) + + def testHash2(self): + NodeList = [] + i = 0 + while i < 100: + i += 1 + NodeList.append(GraphNodesFilter(r'КСРФ/П'+str(i), + datetime.date(i, 10, 16), + datetime.date(i, 10, 17), + (0, 32), (33, 60))) + NodeList = [node.__hash__() for node in NodeList] + TestStatus = True + for node in NodeList: + if NodeList.count(node) != 1: + TestStatus = False + self.assertTrue(TestStatus) + + +class GraphEdgesFilterTestCase(unittest.TestCase): + def setUp(self): + self.edge1 = GraphEdgesFilter( + HeadersFilter(r'КСРФ/П', datetime.date(2018, 10, 16), + datetime.date(2018, 10, 17)), + HeadersFilter(r'КСРФ/П-О', datetime.date(2018, 10, 17), + datetime.date(2018, 10, 18)), + (0, 31)) + self.edge2 = GraphEdgesFilter( + HeadersFilter(r'КСРФ/П', datetime.date(2018, 10, 16), + datetime.date(2018, 10, 17)), + HeadersFilter(r'КСРФ/П-О', datetime.date(2018, 10, 17), + datetime.date(2018, 10, 18)), + (0, 31)) + self.edge3 = GraphEdgesFilter( + HeadersFilter(r'КСРФ/О', datetime.date(2018, 9, 27), + datetime.date(2018, 9, 28)), + HeadersFilter(r'КСРФ/О-О', datetime.date(2018, 9, 28), + datetime.date(2018, 9, 29)), + (0, 30)) + + def testCreate1(self): + try: + self.edge4 = GraphEdgesFilter( + HeadersFilter(r'КСРФ/О', datetime.date(2018, 9, 27), + datetime.date(2018, 9, 28)), + HeadersFilter(r'КСРФ/О-О', datetime.date(2018, 9, 28), + datetime.date(2018, 9, 29)), + (0, 30)) + TestStatus = True + except TypeError: + TestStatus = False + self.assertTrue(TestStatus) + + def testCreate2(self): + try: + self.edge4 = GraphEdgesFilter( + HeadersFilter(r'КСРФ/О', datetime.date(2018, 9, 27), + datetime.date(2018, 9, 28)), + 'HeadersFilter', + (0, 30)) + TestStatus = True + except TypeError: + TestStatus = False + self.assertFalse(TestStatus) + + def testEq1(self): + TestStatus = self.edge1 == self.edge2 + self.assertTrue(TestStatus) + + def testEq2(self): + TestStatus = self.edge1 == self.edge3 + self.assertFalse(TestStatus) + + def testNe1(self): + TestStatus = self.edge1 != self.edge2 + self.assertFalse(TestStatus) + + def testNe2(self): + TestStatus = self.edge1 != self.edge3 + self.assertTrue(TestStatus) + + def testHash1(self): + EdgeList = [] + i = 0 + while i < 100: + i += 1 + EdgeList.append(GraphEdgesFilter( + HeadersFilter(r'КСРФ/П', datetime.date(2018, 10, 16), + datetime.date(2018, 10, 17)), + HeadersFilter(r'КСРФ/П-О', datetime.date(2018, 10, 17), + datetime.date(2018, 10, 18)), + (0, 32))) + TestStatus = True + for edge in EdgeList: + if edge.__hash__ != EdgeList[0].__hash__: + TestStatus = False + self.assertTrue(TestStatus) + + def testHash2(self): + EdgeList = [] + i = 0 + while i < 100: + i += 1 + EdgeList.append(GraphEdgesFilter( + HeadersFilter(r'КСРФ/П', datetime.date(i, 10, 16), + datetime.date(i, 10, 17)), + HeadersFilter(r'КСРФ/П-О', datetime.date(i, 10, 17), + datetime.date(i, 10, 18)), + (0, i))) + EdgeList = [edge.__hash__() for edge in EdgeList] + TestStatus = True + for edge in EdgeList: + if EdgeList.count(edge) != 1: + TestStatus = False + self.assertTrue(TestStatus) + + +class LinkGraphTestCase(unittest.TestCase): + def setUp(self): + self.graph1 = LinkGraph() + self.graph1.add_node( + Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)')) + self.graph1.add_node( + Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)')) + self.graph1.add_edge( + CleanLink( + Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), + Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)'), + 31, (31, 'постановление'))) + self.graph2 = LinkGraph() + self.graph2.add_node( + Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)')) + self.graph2.add_node( + Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)')) + self.graph2.add_edge( + CleanLink( + Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), + Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)'), + 31, (31, 'постановление'))) + self.graph3 = LinkGraph() + self.graph3.add_node( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf')) + self.graph3.add_node( + Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', + datetime.date(2018, 9, 28), + r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf')) + self.graph3.add_edge( + CleanLink( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), + Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', + datetime.date(2018, 9, 28), + r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), + 30, (30, 'определение'))) + + def testCreate1(self): + try: + self.graph4 = LinkGraph() + self.graph4.add_node( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/357727.pdf')) + self.graph4.add_node( + Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', + datetime.date(2018, 9, 28), + r'http://doc.ksrf.ru/decision/357728.pdf')) + self.graph4.add_edge( + CleanLink( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/357727.pdf'), + Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', + datetime.date(2018, 9, 28), + r'http://doc.ksrf.ru/decision/357728.pdf'), + 30, (30, 'определение'))) + TestStatus = True + except TypeError: + TestStatus = False + self.assertTrue(TestStatus) + + def testCreate2(self): + try: + self.graph4 = LinkGraph() + self.graph4.add_node( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/357727.pdf')) + self.graph4.add_node( + Header(r'КСРФ/31-О/2018', r'КСРФ/О', 14, + datetime.date(2018, 9, 28), + r'http://doc.ksrf.ru/decision/357728.pdf')) + self.graph4.add_edge( + CleanLink( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/357727.pdf'), + Header(r'КСРФ/31-О/2018', False, 'uvidimsya', + datetime.date(2018, 9, 28), + r'http://doc.ksrf.ru/decision/357728.pdf'), + 30, (30, 322))) + TestStatus = True + except TypeError: + TestStatus = False + self.assertFalse(TestStatus) + + def testEq1(self): + TestStatus = self.graph1 == self.graph2 + self.assertTrue(TestStatus) + + def testEq2(self): + TestStatus = self.graph1 == self.graph3 + self.assertFalse(TestStatus) + + def testNe1(self): + TestStatus = self.graph1 != self.graph2 + self.assertFalse(TestStatus) + + def testNe2(self): + TestStatus = self.graph1 != self.graph3 + self.assertTrue(TestStatus) + + def testHash1(self): + GraphList = [] + i = 0 + while i < 100: + i += 1 + self.graph = LinkGraph() + self.graph.add_node( + Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/357646.pdf')) + self.graph.add_node( + Header(r'КСРФ/33-П/2018', r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/357647.pdf')) + self.graph.add_edge( + CleanLink( + Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/357646.pdf'), + Header(r'КСРФ/33-П/2018', r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/357647.pdf'), + 32, (32, 'постановление'))) + GraphList.append(self.graph) + TestStatus = True + for graph in GraphList: + if graph.__hash__ != GraphList[0].__hash__: + TestStatus = False + self.assertTrue(TestStatus) + + def testHash2(self): + GraphList = [] + i = 0 + while i < 100: + i += 1 + self.graph = LinkGraph() + self.graph.add_node( + Header(r'КСРФ/'+str(i)+r'-П/2018', + r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/357646.pdf')) + self.graph.add_node( + Header(r'КСРФ/'+str(i+1)+r'-П/2018', + r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/357647.pdf')) + self.graph.add_edge( + CleanLink( + Header(r'КСРФ/'+str(i)+r'-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/357646.pdf'), + Header(r'КСРФ/'+str(i+1)+r'-П/2018', r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/357647.pdf'), + 32, (32, 'постановление'))) + GraphList.append(self.graph) + HashList = [] + for graph in GraphList: + HashList.append(self.graph.__hash__()) + TestStatus = True + for graph in GraphList: + if GraphList.count(graph) != 1: + TestStatus = False + self.assertTrue(TestStatus) + + +suite = unittest.TestLoader().loadTestsFromTestCase(DocumentHeaderTestCase) +unittest.TextTestRunner(verbosity=2).run(suite) +suite = unittest.TestLoader().loadTestsFromTestCase(HeaderTestCase) +unittest.TextTestRunner(verbosity=2).run(suite) +suite = unittest.TestLoader().loadTestsFromTestCase(DuplicateHeaderTestCase) +unittest.TextTestRunner(verbosity=2).run(suite) +suite = unittest.TestLoader().loadTestsFromTestCase(LinkTestCase) +unittest.TextTestRunner(verbosity=2).run(suite) +suite = unittest.TestLoader().loadTestsFromTestCase(RoughLinkTestCase) +unittest.TextTestRunner(verbosity=2).run(suite) +suite = unittest.TestLoader().loadTestsFromTestCase(CleanLinkTestCase) +unittest.TextTestRunner(verbosity=2).run(suite) +suite = unittest.TestLoader().loadTestsFromTestCase(HeadersFilterTestCase) +unittest.TextTestRunner(verbosity=2).run(suite) +suite = unittest.TestLoader().loadTestsFromTestCase(GraphNodesFilterTestCase) +unittest.TextTestRunner(verbosity=2).run(suite) +suite = unittest.TestLoader().loadTestsFromTestCase(GraphEdgesFilterTestCase) +unittest.TextTestRunner(verbosity=2).run(suite) +suite = unittest.TestLoader().loadTestsFromTestCase(LinkGraphTestCase) +unittest.TextTestRunner(verbosity=2).run(suite) + +if __name__ == '__main__': + unittest.main() diff --git a/link_analysis/testrough.py b/link_analysis/testrough.py new file mode 100644 index 0000000..a7ecc00 --- /dev/null +++ b/link_analysis/testrough.py @@ -0,0 +1,62 @@ +import datetime +import collections +import unittest +from models import DocumentHeader, Header, DuplicateHeader, Link, RoughLink +from models import CleanLink, HeadersFilter, GraphNodesFilter, GraphEdgesFilter +from models import LinkGraph + + +class RoughAnalysisTestCase(unittest.TestCase): + def setUp(self): + self.header1 = DocumentHeader(r'КСРФ/31-П/2018') + self.header2 = DocumentHeader(r'КСРФ/31-П/2018') + self.header3 = DocumentHeader(r'КСРФ/30-П/2018') + + def testCreate(self): + try: + self.header4 = DocumentHeader(True) + TestStatus = True + except TypeError: + TestStatus = False + self.assertTrue(TestStatus) + + def testEq1(self): + TestStatus = self.header1 == self.header2 + self.assertTrue(TestStatus) + + def testEq2(self): + TestStatus = self.header1 == self.header3 + self.assertFalse(TestStatus) + + def testNe1(self): + TestStatus = self.header1 != self.header2 + self.assertFalse(TestStatus) + + def testNe2(self): + TestStatus = self.header1 != self.header3 + self.assertTrue(TestStatus) + + def testHash1(self): + HeaderList = [] + i = 0 + while i < 100: + i += 1 + HeaderList.append(DocumentHeader(r'КСРФ/32-П/2018')) + TestStatus = True + for header in HeaderList: + if header.__hash__ != HeaderList[0].__hash__: + TestStatus = False + self.assertTrue(TestStatus) + + def testHash2(self): + HeaderList = [] + i = 0 + while i < 100: + i += 1 + HeaderList.append(DocumentHeader(r'КСРФ/'+str(i)+r'-П/2018')) + HeaderList = [header.__hash__() for header in HeaderList] + TestStatus = True + for header in HeaderList: + if HeaderList.count(header) != 1: + TestStatus = False + self.assertTrue(TestStatus) \ No newline at end of file From 0422f39bb810645546162c24fd669bb9b2c7eb05 Mon Sep 17 00:00:00 2001 From: Drokonor Date: Thu, 25 Oct 2018 12:30:42 +0300 Subject: [PATCH 2/3] test --- link_analysis/rough_analysis.py | 2 +- link_analysis/testclean.py | 46 +++++++ link_analysis/testmodels.py | 233 ++++++++++++++++++++------------ link_analysis/testrough.py | 126 +++++++++++------ 4 files changed, 275 insertions(+), 132 deletions(-) create mode 100644 link_analysis/testclean.py diff --git a/link_analysis/rough_analysis.py b/link_analysis/rough_analysis.py index 50705c6..2cb7139 100644 --- a/link_analysis/rough_analysis.py +++ b/link_analysis/rough_analysis.py @@ -39,7 +39,7 @@ def get_rough_links(header: Header) -> List[RoughLink]: :param header: instance of class models.Header """ try: - with open(header.text_location, 'r', encoding="utf-8") as file: + with open(header.text_location, 'r', encoding='utf-8') as file: text = file.read() except TypeError: return TypeError diff --git a/link_analysis/testclean.py b/link_analysis/testclean.py new file mode 100644 index 0000000..b5a869b --- /dev/null +++ b/link_analysis/testclean.py @@ -0,0 +1,46 @@ +import datetime +import collections +import unittest +from models import DocumentHeader, Header, DuplicateHeader, Link, RoughLink +from models import CleanLink, HeadersFilter, GraphNodesFilter, GraphEdgesFilter +from models import LinkGraph +from final_analysis import get_clean_links + + +class FinalAnalysisTestCase(unittest.TestCase): + def testClean1(self): + header1 = Header( + 'text1', 'txt', 'text1', + datetime.date(2018, 10, 24), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', + r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test1.txt') + RoughList = [ + RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 420-О', 'О', 31), + RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 13 421-П', 'П', 31), + RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 422-Р', 'Р', 31), + RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 423-О-П', 'О-П', 31)] + CleanList = ['от 8 октября 2007 года № 420-О', + 'от 8 октября 2007 года № 13 421-П', + 'от 8 октября 2007 года № 423-О-П'] + DesicionID = 'text1' + TestStatus = True + if get_clean_links({header1: RoughList}, + {DesicionID: header1})[0].get(header1) != CleanList: + TestStatus = False + self.assertTrue(TestStatus) + +suite = unittest.TestLoader().loadTestsFromTestCase(FinalAnalysisTestCase) +unittest.TextTestRunner(verbosity=2).run(suite) +header1 = Header( + 'text1', 'txt', 'text1', + datetime.date(2018, 10, 24), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', + r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test1.txt') +RoughList = [ + RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 420-О', 'О', 89), + RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 13 421-П', 'П', 48), + RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 422-Р', 'Р', 48), + RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 423-О-П', 'О-П', 48)] +DesicionID = 'text1' +print(get_clean_links({header1: RoughList}, + {DesicionID: header1})[0].get(header1)) diff --git a/link_analysis/testmodels.py b/link_analysis/testmodels.py index 37c3007..ae7d609 100644 --- a/link_analysis/testmodels.py +++ b/link_analysis/testmodels.py @@ -12,7 +12,7 @@ def setUp(self): self.header2 = DocumentHeader(r'КСРФ/31-П/2018') self.header3 = DocumentHeader(r'КСРФ/30-П/2018') - def testCreate1(self): + def testCreateWithCorrectArguments(self): try: self.header4 = DocumentHeader(r'КСРФ/31-П/2018') TestStatus = True @@ -20,7 +20,7 @@ def testCreate1(self): TestStatus = False self.assertTrue(TestStatus) - def testCreate2(self): + def testCreateWithIncorrectArguments(self): try: self.header4 = DocumentHeader(True) TestStatus = True @@ -28,23 +28,23 @@ def testCreate2(self): TestStatus = False self.assertFalse(TestStatus) - def testEq1(self): + def testEqWithEqualClasses(self): TestStatus = self.header1 == self.header2 self.assertTrue(TestStatus) - def testEq2(self): + def testEqWithUnequalClasses(self): TestStatus = self.header1 == self.header3 self.assertFalse(TestStatus) - def testNe1(self): + def testNeWithUnequalClasses(self): TestStatus = self.header1 != self.header2 self.assertFalse(TestStatus) - def testNe2(self): + def testNeWithEqualClasses(self): TestStatus = self.header1 != self.header3 self.assertTrue(TestStatus) - def testHash1(self): + def testHashWithSameClasses(self): HeaderList = [] i = 0 while i < 100: @@ -56,7 +56,7 @@ def testHash1(self): TestStatus = False self.assertTrue(TestStatus) - def testHash2(self): + def testHashWithDifferentClasses(self): HeaderList = [] i = 0 while i < 100: @@ -85,7 +85,7 @@ def setUp(self): datetime.date(2018, 9, 27), r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') - def testCreate1(self): + def testCreateWithCorrectArguments(self): try: self.header4 = Header( r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', @@ -96,7 +96,7 @@ def testCreate1(self): TestStatus = False self.assertTrue(TestStatus) - def testCreate2(self): + def testCreateWithIncorrectArguments(self): try: self.header4 = Header( r'КСРФ/30-О/2018', 12, False, @@ -107,23 +107,23 @@ def testCreate2(self): TestStatus = False self.assertFalse(TestStatus) - def testEq1(self): + def testEqWithEqualClasses(self): TestStatus = self.header1 == self.header2 self.assertTrue(TestStatus) - def testEq2(self): + def testEqWithUnequalClasses(self): TestStatus = self.header1 == self.header3 self.assertFalse(TestStatus) - def testNe1(self): + def testNeWithUnequalClasses(self): TestStatus = self.header1 != self.header2 self.assertFalse(TestStatus) - def testNe2(self): + def testNeWithEqualClasses(self): TestStatus = self.header1 != self.header3 self.assertTrue(TestStatus) - def testHash1(self): + def testHashWithSameClasses(self): HeaderList = [] i = 0 while i < 100: @@ -138,7 +138,7 @@ def testHash1(self): TestStatus = False self.assertTrue(TestStatus) - def testHash2(self): + def testHashWithDifferentClasses(self): HeaderList = [] i = 0 while i < 100: @@ -170,7 +170,7 @@ def setUp(self): datetime.date(2018, 9, 27), r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') - def testCreate1(self): + def testCreateWithCorrectArguments(self): try: self.header4 = DuplicateHeader( r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', @@ -181,7 +181,7 @@ def testCreate1(self): TestStatus = False self.assertTrue(TestStatus) - def testCreate2(self): + def testCreateWithIncorrectArguments(self): try: self.header4 = DuplicateHeader( r'КСРФ/30-О/2018', r'КСРФ/О', 1488, @@ -192,23 +192,23 @@ def testCreate2(self): TestStatus = False self.assertFalse(TestStatus) - def testEq1(self): + def testEqWithEqualClasses(self): TestStatus = self.header1 == self.header2 self.assertTrue(TestStatus) - def testEq2(self): + def testEqWithUnequalClasses(self): TestStatus = self.header1 == self.header3 self.assertFalse(TestStatus) - def testNe1(self): + def testNeWithUnequalClasses(self): TestStatus = self.header1 != self.header2 self.assertFalse(TestStatus) - def testNe2(self): + def testNeWithEqualClasses(self): TestStatus = self.header1 != self.header3 self.assertTrue(TestStatus) - def testHash1(self): + def testHashWithSameClasses(self): HeaderList = [] i = 0 while i < 100: @@ -223,7 +223,7 @@ def testHash1(self): TestStatus = False self.assertTrue(TestStatus) - def testHash2(self): + def testHashWithDifferentClasses(self): HeaderList = [] i = 0 while i < 100: @@ -256,7 +256,7 @@ def setUp(self): datetime.date(2018, 9, 27), r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf')) - def testCreate1(self): + def testCreateWithCorrectArguments(self): try: self.link4 = Link( Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', @@ -268,7 +268,7 @@ def testCreate1(self): TestStatus = False self.assertTrue(TestStatus) - def testCreate2(self): + def testCreateWithIncorrectArguments(self): try: self.link4 = Link( Header(True, r'КСРФ/О', 'zdarova', @@ -279,23 +279,23 @@ def testCreate2(self): TestStatus = False self.assertFalse(TestStatus) - def testEq1(self): + def testEqWithEqualClasses(self): TestStatus = self.link1 == self.link2 self.assertTrue(TestStatus) - def testEq2(self): + def testEqWithUnequalClasses(self): TestStatus = self.link1 == self.link3 self.assertFalse(TestStatus) - def testNe1(self): + def testNeWithUnequalClasses(self): TestStatus = self.link1 != self.link2 self.assertFalse(TestStatus) - def testNe2(self): + def testNeWithEqualClasses(self): TestStatus = self.link1 != self.link3 self.assertTrue(TestStatus) - def testHash1(self): + def testHashWithSameClasses(self): LinkList = [] i = 0 while i < 100: @@ -310,7 +310,7 @@ def testHash1(self): TestStatus = False self.assertTrue(TestStatus) - def testHash2(self): + def testHashWithDifferentClasses(self): LinkList = [] i = 0 while i < 100: @@ -334,57 +334,57 @@ def setUp(self): Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', datetime.date(2018, 10, 16), r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), - 'постановление', 'от 1 мая 2018 года № 31-П', 31) + 'от 1 мая 2018 года № 31-П', 'постановление', 31) self.link2 = RoughLink( Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', datetime.date(2018, 10, 16), r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), - 'постановление', 'от 1 мая 2018 года № 31-П', 31) + 'от 1 мая 2018 года № 31-П', 'постановление', 31) self.link3 = RoughLink( Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', datetime.date(2018, 9, 27), r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), - 'определение', 'от 2 мая 2018 года № 30-О', 30) + 'от 2 мая 2018 года № 30-О', 'определение', 30) - def testCreate1(self): + def testCreateWithCorrectArguments(self): try: self.link4 = RoughLink( Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', datetime.date(2018, 9, 27), r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), - 'определение', 'от 2 мая 2018 года № 30-О', 30) + 'от 2 мая 2018 года № 30-О', 'определение', 30) TestStatus = True except TypeError: TestStatus = False self.assertTrue(TestStatus) - def testCreate2(self): + def testCreateWithIncorrectArguments(self): try: self.link4 = RoughLink( 'Header', - 'определение', 'от 2 мая 2018 года № 30-О', 30) + 'от 2 мая 2018 года № 30-О', 'определение', 30) TestStatus = True except TypeError: TestStatus = False self.assertFalse(TestStatus) - def testEq1(self): + def testEqWithEqualClasses(self): TestStatus = self.link1 == self.link2 self.assertTrue(TestStatus) - def testEq2(self): + def testEqWithUnequalClasses(self): TestStatus = self.link1 == self.link3 self.assertFalse(TestStatus) - def testNe1(self): + def testNeWithUnequalClasses(self): TestStatus = self.link1 != self.link2 self.assertFalse(TestStatus) - def testNe2(self): + def testNeWithEqualClasses(self): TestStatus = self.link1 != self.link3 self.assertTrue(TestStatus) - def testHash1(self): + def testHashWithSameClasses(self): LinkList = [] i = 0 while i < 100: @@ -393,14 +393,14 @@ def testHash1(self): Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', datetime.date(2018, 10, 16), r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf'), - 'постановление', 'от 3 мая 2018 года № 32-П', 32)) + 'от 3 мая 2018 года № 32-П', 'постановление', 32)) TestStatus = True for link in LinkList: if link.__hash__ != LinkList[0].__hash__: TestStatus = False self.assertTrue(TestStatus) - def testHash2(self): + def testHashWithDifferentClasses(self): LinkList = [] i = 0 while i < 100: @@ -410,7 +410,7 @@ def testHash2(self): r'КСРФ/П', 'privet', datetime.date(2018, 10, 16), r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf'), - 'постановление', 'от 3 мая 2018 года № 32-П', 32)) + 'от 3 мая 2018 года № 32-П', 'постановление', 32)) LinkList = [link.__hash__() for link in LinkList] TestStatus = True for link in LinkList: @@ -446,7 +446,7 @@ def setUp(self): r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), 30, (30, 'определение')) - def testCreate1(self): + def testCreateWithCorrectArguments(self): try: self.link4 = CleanLink( Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', @@ -461,7 +461,7 @@ def testCreate1(self): TestStatus = False self.assertTrue(TestStatus) - def testCreate2(self): + def testCreateWithIncorrectArguments(self): try: self.link4 = CleanLink( Header(r'КСРФ/30-О/2018', 228, 'zdarova', @@ -476,23 +476,23 @@ def testCreate2(self): TestStatus = False self.assertFalse(TestStatus) - def testEq1(self): + def testEqWithEqualClasses(self): TestStatus = self.link1 == self.link2 self.assertTrue(TestStatus) - def testEq2(self): + def testEqWithUnequalClasses(self): TestStatus = self.link1 == self.link3 self.assertFalse(TestStatus) - def testNe1(self): + def testNeWithUnequalClasses(self): TestStatus = self.link1 != self.link2 self.assertFalse(TestStatus) - def testNe2(self): + def testNeWithEqualClasses(self): TestStatus = self.link1 != self.link3 self.assertTrue(TestStatus) - def testHash1(self): + def testHashWithSameClasses(self): LinkList = [] i = 0 while i < 100: @@ -511,7 +511,7 @@ def testHash1(self): TestStatus = False self.assertTrue(TestStatus) - def testHash2(self): + def testHashWithDifferentClasses(self): LinkList = [] i = 0 while i < 100: @@ -543,7 +543,7 @@ def setUp(self): self.header3 = HeadersFilter(r'КСРФ/О', datetime.date(2018, 9, 27), datetime.date(2018, 9, 28)) - def testCreate1(self): + def testCreateWithCorrectArguments(self): try: self.header4 = HeadersFilter(r'КСРФ/О', datetime.date(2018, 9, 27), @@ -553,7 +553,7 @@ def testCreate1(self): TestStatus = False self.assertTrue(TestStatus) - def testCreate2(self): + def testCreateWithIncorrectArguments(self): try: self.header4 = HeadersFilter(r'КСРФ/О', True, @@ -563,23 +563,23 @@ def testCreate2(self): TestStatus = False self.assertFalse(TestStatus) - def testEq1(self): + def testEqWithEqualClasses(self): TestStatus = self.header1 == self.header2 self.assertTrue(TestStatus) - def testEq2(self): + def testEqWithUnequalClasses(self): TestStatus = self.header1 == self.header3 self.assertFalse(TestStatus) - def testNe1(self): + def testNeWithUnequalClasses(self): TestStatus = self.header1 != self.header2 self.assertFalse(TestStatus) - def testNe2(self): + def testNeWithEqualClasses(self): TestStatus = self.header1 != self.header3 self.assertTrue(TestStatus) - def testHash1(self): + def testHashWithSameClasses(self): HeaderList = [] i = 0 while i < 100: @@ -593,7 +593,7 @@ def testHash1(self): TestStatus = False self.assertTrue(TestStatus) - def testHash2(self): + def testHashWithDifferentClasses(self): HeaderList = [] i = 0 while i < 100: @@ -608,17 +608,27 @@ def testHash2(self): TestStatus = False self.assertTrue(TestStatus) - def testFilteredHeaders(self): + def testGetFilteredHeadersWithNotEmptyFilter(self): HeadersDict = {r'КСРФ/31-П/2018': Header( r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', datetime.date(2018, 10, 16), r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf')} TestStatus = True - self.header4 = HeadersFilter() if self.header1.get_filtered_headers(HeadersDict) is None: TestStatus = False self.assertTrue(TestStatus) + def testGetFilteredHeadersWithEmptyFilter(self): + HeadersDict = {r'КСРФ/31-П/2018': Header( + r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf')} + TestStatus = True + self.header4 = HeadersFilter() + if self.header4.get_filtered_headers(HeadersDict) is None: + TestStatus = False + self.assertTrue(TestStatus) + class GraphNodesFilterTestCase(unittest.TestCase): def setUp(self): @@ -632,7 +642,7 @@ def setUp(self): datetime.date(2018, 9, 28), (0, 30), (31, 60)) - def testCreate1(self): + def testCreateWithCorrectArguments(self): try: self.node4 = GraphNodesFilter(r'КСРФ/О', datetime.date(2018, 9, 27), @@ -643,7 +653,7 @@ def testCreate1(self): TestStatus = False self.assertTrue(TestStatus) - def testCreate2(self): + def testCreateWithIncorrectArguments(self): try: self.node4 = GraphNodesFilter(r'КСРФ/О', datetime.date(2018, 9, 27), @@ -654,23 +664,23 @@ def testCreate2(self): TestStatus = False self.assertFalse(TestStatus) - def testEq1(self): + def testEqWithEqualClasses(self): TestStatus = self.node1 == self.node2 self.assertTrue(TestStatus) - def testEq2(self): + def testEqWithUnequalClasses(self): TestStatus = self.node1 == self.node3 self.assertFalse(TestStatus) - def testNe1(self): + def testNeWithUnequalClasses(self): TestStatus = self.node1 != self.node2 self.assertFalse(TestStatus) - def testNe2(self): + def testNeWithEqualClasses(self): TestStatus = self.node1 != self.node3 self.assertTrue(TestStatus) - def testHash1(self): + def testHashWithSameClasses(self): NodeList = [] i = 0 while i < 100: @@ -685,7 +695,7 @@ def testHash1(self): TestStatus = False self.assertTrue(TestStatus) - def testHash2(self): + def testHashWithDifferentClasses(self): NodeList = [] i = 0 while i < 100: @@ -723,7 +733,7 @@ def setUp(self): datetime.date(2018, 9, 29)), (0, 30)) - def testCreate1(self): + def testCreateWithCorrectArguments(self): try: self.edge4 = GraphEdgesFilter( HeadersFilter(r'КСРФ/О', datetime.date(2018, 9, 27), @@ -736,7 +746,7 @@ def testCreate1(self): TestStatus = False self.assertTrue(TestStatus) - def testCreate2(self): + def testCreateWithIncorrectArguments(self): try: self.edge4 = GraphEdgesFilter( HeadersFilter(r'КСРФ/О', datetime.date(2018, 9, 27), @@ -748,23 +758,23 @@ def testCreate2(self): TestStatus = False self.assertFalse(TestStatus) - def testEq1(self): + def testEqWithEqualClasses(self): TestStatus = self.edge1 == self.edge2 self.assertTrue(TestStatus) - def testEq2(self): + def testEqWithUnequalClasses(self): TestStatus = self.edge1 == self.edge3 self.assertFalse(TestStatus) - def testNe1(self): + def testNeWithUnequalClasses(self): TestStatus = self.edge1 != self.edge2 self.assertFalse(TestStatus) - def testNe2(self): + def testNeWithEqualClasses(self): TestStatus = self.edge1 != self.edge3 self.assertTrue(TestStatus) - def testHash1(self): + def testHashWithSameClasses(self): EdgeList = [] i = 0 while i < 100: @@ -781,7 +791,7 @@ def testHash1(self): TestStatus = False self.assertTrue(TestStatus) - def testHash2(self): + def testHashWithDifferentClasses(self): EdgeList = [] i = 0 while i < 100: @@ -799,6 +809,51 @@ def testHash2(self): TestStatus = False self.assertTrue(TestStatus) + def testGetFilteredEdgesWithNotEmptyFilter(self): + Edges = [CleanLink( + Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), + Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)'), + 31, (31, 'постановление')), + CleanLink( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), + Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', + datetime.date(2018, 9, 28), + r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), + 30, (30, 'определение'))] + TestStatus = True + if self.edge1.get_filtered_edges(Edges) is None: + TestStatus = False + self.assertTrue(TestStatus) + + def testGetFilteredEdgesWithEmptyFilter(self): + Edges = [CleanLink( + Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', + datetime.date(2018, 10, 16), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), + Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', + datetime.date(2018, 10, 17), + r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)'), + 31, (31, 'постановление')), + CleanLink( + Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', + datetime.date(2018, 9, 27), + r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), + Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', + datetime.date(2018, 9, 28), + r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), + 30, (30, 'определение'))] + TestStatus = True + self.edge4 = GraphEdgesFilter() + if self.edge4.get_filtered_edges(Edges) is None: + TestStatus = False + self.assertTrue(TestStatus) + class LinkGraphTestCase(unittest.TestCase): def setUp(self): @@ -857,7 +912,7 @@ def setUp(self): r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), 30, (30, 'определение'))) - def testCreate1(self): + def testCreateWithCorrectArguments(self): try: self.graph4 = LinkGraph() self.graph4.add_node( @@ -882,7 +937,7 @@ def testCreate1(self): TestStatus = False self.assertTrue(TestStatus) - def testCreate2(self): + def testCreateWithIncorrectArguments(self): try: self.graph4 = LinkGraph() self.graph4.add_node( @@ -907,23 +962,23 @@ def testCreate2(self): TestStatus = False self.assertFalse(TestStatus) - def testEq1(self): + def testEqWithEqualClasses(self): TestStatus = self.graph1 == self.graph2 self.assertTrue(TestStatus) - def testEq2(self): + def testEqWithUnequalClasses(self): TestStatus = self.graph1 == self.graph3 self.assertFalse(TestStatus) - def testNe1(self): + def testNeWithUnequalClasses(self): TestStatus = self.graph1 != self.graph2 self.assertFalse(TestStatus) - def testNe2(self): + def testNeWithEqualClasses(self): TestStatus = self.graph1 != self.graph3 self.assertTrue(TestStatus) - def testHash1(self): + def testHashWithSameClasses(self): GraphList = [] i = 0 while i < 100: @@ -953,7 +1008,7 @@ def testHash1(self): TestStatus = False self.assertTrue(TestStatus) - def testHash2(self): + def testHashWithDifferentClasses(self): GraphList = [] i = 0 while i < 100: diff --git a/link_analysis/testrough.py b/link_analysis/testrough.py index a7ecc00..abc6ccf 100644 --- a/link_analysis/testrough.py +++ b/link_analysis/testrough.py @@ -4,59 +4,101 @@ from models import DocumentHeader, Header, DuplicateHeader, Link, RoughLink from models import CleanLink, HeadersFilter, GraphNodesFilter, GraphEdgesFilter from models import LinkGraph +from rough_analysis import get_rough_links class RoughAnalysisTestCase(unittest.TestCase): - def setUp(self): - self.header1 = DocumentHeader(r'КСРФ/31-П/2018') - self.header2 = DocumentHeader(r'КСРФ/31-П/2018') - self.header3 = DocumentHeader(r'КСРФ/30-П/2018') - - def testCreate(self): - try: - self.header4 = DocumentHeader(True) - TestStatus = True - except TypeError: + def testRough1(self): + header1 = Header( + 'text1', 'txt', 'text1', + datetime.date(2018, 10, 24), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', + r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test1.txt') + RoughList = ['от 31 8 октября 23 2007 42 года № 420-О', + 'от 31 8 октября 23 2007 42 года № 13 421-П', + 'от 31 8 октября 23 2007 42 года № 422-Р', + 'от 31 8 октября 23 2007 42 года № 423-О-П'] + TestStatus = True + BodyList = [] + for roughlink in get_rough_links(header1): + BodyList.append(roughlink.body) + if BodyList != RoughList: TestStatus = False self.assertTrue(TestStatus) - def testEq1(self): - TestStatus = self.header1 == self.header2 + def testRough2(self): + header1 = Header( + 'text2', 'txt', 'text2', + datetime.date(2018, 10, 24), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', + r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test2.txt') + RoughList = ['от 322 16 228 мая 007 1998 1488 года № 1707 80-Л-О-Л-З-А-А-Л-Ь-Я-Н-С'] + TestStatus = True + BodyList = [] + for roughlink in get_rough_links(header1): + BodyList.append(roughlink.body) + if BodyList != RoughList: + TestStatus = False self.assertTrue(TestStatus) - def testEq2(self): - TestStatus = self.header1 == self.header3 - self.assertFalse(TestStatus) - - def testNe1(self): - TestStatus = self.header1 != self.header2 - self.assertFalse(TestStatus) - - def testNe2(self): - TestStatus = self.header1 != self.header3 + def testRough3(self): + header1 = Header( + 'text3', 'txt', 'text3', + datetime.date(2018, 10, 24), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', + r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test3.txt') + RoughList = ['от 4444 44444444 4444 28 4221 декабря 2111 2019 года № 1111111-J-P-E'] + TestStatus = True + BodyList = [] + for roughlink in get_rough_links(header1): + BodyList.append(roughlink.body) + if BodyList != RoughList: + TestStatus = False self.assertTrue(TestStatus) - def testHash1(self): - HeaderList = [] - i = 0 - while i < 100: - i += 1 - HeaderList.append(DocumentHeader(r'КСРФ/32-П/2018')) + def testRough4(self): + header1 = Header( + 'text4', 'txt', 'text4', + datetime.date(2018, 10, 24), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', + r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test4.txt') + RoughList = ['от 23 2 февраля 222 2005 133 года № 18-Г-О', + 'от 23 2 февраля 222 2005 133 года № 13 19-Ю-S', + 'от 23 2 февраля 222 2005 133 года № 20-R', + 'от 23 2 февраля 222 2005 133 года № 21-U-F-C', + 'от 28 марта 2014 года № 300-О-П'] TestStatus = True - for header in HeaderList: - if header.__hash__ != HeaderList[0].__hash__: - TestStatus = False + BodyList = [] + for roughlink in get_rough_links(header1): + BodyList.append(roughlink.body) + if BodyList != RoughList: + TestStatus = False self.assertTrue(TestStatus) - def testHash2(self): - HeaderList = [] - i = 0 - while i < 100: - i += 1 - HeaderList.append(DocumentHeader(r'КСРФ/'+str(i)+r'-П/2018')) - HeaderList = [header.__hash__() for header in HeaderList] + def testRough5(self): + header1 = Header( + 'text5', 'txt', 'text5', + datetime.date(2018, 10, 24), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', + r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test5.txt') + RoughList = ['от 24 декабря 1992 года № 123-А'] TestStatus = True - for header in HeaderList: - if HeaderList.count(header) != 1: - TestStatus = False - self.assertTrue(TestStatus) \ No newline at end of file + BodyList = [] + for roughlink in get_rough_links(header1): + BodyList.append(roughlink.body) + if BodyList != RoughList: + TestStatus = False + self.assertTrue(TestStatus) + + +suite = unittest.TestLoader().loadTestsFromTestCase(RoughAnalysisTestCase) +unittest.TextTestRunner(verbosity=2).run(suite) +''' +header1 = Header( + 'text5', 'txt', 'text5', + datetime.date(2018, 10, 24), + r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', + r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test5.txt') +for roughlink in get_rough_links(header1): + print(roughlink.body) +''' From 1fe6858c8876d412fdc47e7d96b0714dfeb5bae8 Mon Sep 17 00:00:00 2001 From: Drokonor Date: Fri, 26 Oct 2018 16:47:15 +0300 Subject: [PATCH 3/3] test for link analysis --- link_analysis/testclean.py | 46 -- link_analysis/testmodels.py | 1069 ----------------------------------- link_analysis/testrough.py | 104 ---- 3 files changed, 1219 deletions(-) delete mode 100644 link_analysis/testclean.py delete mode 100644 link_analysis/testmodels.py delete mode 100644 link_analysis/testrough.py diff --git a/link_analysis/testclean.py b/link_analysis/testclean.py deleted file mode 100644 index b5a869b..0000000 --- a/link_analysis/testclean.py +++ /dev/null @@ -1,46 +0,0 @@ -import datetime -import collections -import unittest -from models import DocumentHeader, Header, DuplicateHeader, Link, RoughLink -from models import CleanLink, HeadersFilter, GraphNodesFilter, GraphEdgesFilter -from models import LinkGraph -from final_analysis import get_clean_links - - -class FinalAnalysisTestCase(unittest.TestCase): - def testClean1(self): - header1 = Header( - 'text1', 'txt', 'text1', - datetime.date(2018, 10, 24), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', - r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test1.txt') - RoughList = [ - RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 420-О', 'О', 31), - RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 13 421-П', 'П', 31), - RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 422-Р', 'Р', 31), - RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 423-О-П', 'О-П', 31)] - CleanList = ['от 8 октября 2007 года № 420-О', - 'от 8 октября 2007 года № 13 421-П', - 'от 8 октября 2007 года № 423-О-П'] - DesicionID = 'text1' - TestStatus = True - if get_clean_links({header1: RoughList}, - {DesicionID: header1})[0].get(header1) != CleanList: - TestStatus = False - self.assertTrue(TestStatus) - -suite = unittest.TestLoader().loadTestsFromTestCase(FinalAnalysisTestCase) -unittest.TextTestRunner(verbosity=2).run(suite) -header1 = Header( - 'text1', 'txt', 'text1', - datetime.date(2018, 10, 24), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', - r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test1.txt') -RoughList = [ - RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 420-О', 'О', 89), - RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 13 421-П', 'П', 48), - RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 422-Р', 'Р', 48), - RoughLink(header1, 'от 31 8 октября 23 2007 42 года № 423-О-П', 'О-П', 48)] -DesicionID = 'text1' -print(get_clean_links({header1: RoughList}, - {DesicionID: header1})[0].get(header1)) diff --git a/link_analysis/testmodels.py b/link_analysis/testmodels.py deleted file mode 100644 index ae7d609..0000000 --- a/link_analysis/testmodels.py +++ /dev/null @@ -1,1069 +0,0 @@ -import datetime -import collections -import unittest -from models import DocumentHeader, Header, DuplicateHeader, Link, RoughLink -from models import CleanLink, HeadersFilter, GraphNodesFilter, GraphEdgesFilter -from models import LinkGraph - - -class DocumentHeaderTestCase(unittest.TestCase): - def setUp(self): - self.header1 = DocumentHeader(r'КСРФ/31-П/2018') - self.header2 = DocumentHeader(r'КСРФ/31-П/2018') - self.header3 = DocumentHeader(r'КСРФ/30-П/2018') - - def testCreateWithCorrectArguments(self): - try: - self.header4 = DocumentHeader(r'КСРФ/31-П/2018') - TestStatus = True - except TypeError: - TestStatus = False - self.assertTrue(TestStatus) - - def testCreateWithIncorrectArguments(self): - try: - self.header4 = DocumentHeader(True) - TestStatus = True - except TypeError: - TestStatus = False - self.assertFalse(TestStatus) - - def testEqWithEqualClasses(self): - TestStatus = self.header1 == self.header2 - self.assertTrue(TestStatus) - - def testEqWithUnequalClasses(self): - TestStatus = self.header1 == self.header3 - self.assertFalse(TestStatus) - - def testNeWithUnequalClasses(self): - TestStatus = self.header1 != self.header2 - self.assertFalse(TestStatus) - - def testNeWithEqualClasses(self): - TestStatus = self.header1 != self.header3 - self.assertTrue(TestStatus) - - def testHashWithSameClasses(self): - HeaderList = [] - i = 0 - while i < 100: - i += 1 - HeaderList.append(DocumentHeader(r'КСРФ/32-П/2018')) - TestStatus = True - for header in HeaderList: - if header.__hash__ != HeaderList[0].__hash__: - TestStatus = False - self.assertTrue(TestStatus) - - def testHashWithDifferentClasses(self): - HeaderList = [] - i = 0 - while i < 100: - i += 1 - HeaderList.append(DocumentHeader(r'КСРФ/'+str(i)+r'-П/2018')) - HeaderList = [header.__hash__() for header in HeaderList] - TestStatus = True - for header in HeaderList: - if HeaderList.count(header) != 1: - TestStatus = False - self.assertTrue(TestStatus) - - -class HeaderTestCase(unittest.TestCase): - def setUp(self): - self.header1 = Header( - r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf') - self.header2 = Header( - r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf') - self.header3 = Header( - r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') - - def testCreateWithCorrectArguments(self): - try: - self.header4 = Header( - r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') - TestStatus = True - except TypeError: - TestStatus = False - self.assertTrue(TestStatus) - - def testCreateWithIncorrectArguments(self): - try: - self.header4 = Header( - r'КСРФ/30-О/2018', 12, False, - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') - TestStatus = True - except TypeError: - TestStatus = False - self.assertFalse(TestStatus) - - def testEqWithEqualClasses(self): - TestStatus = self.header1 == self.header2 - self.assertTrue(TestStatus) - - def testEqWithUnequalClasses(self): - TestStatus = self.header1 == self.header3 - self.assertFalse(TestStatus) - - def testNeWithUnequalClasses(self): - TestStatus = self.header1 != self.header2 - self.assertFalse(TestStatus) - - def testNeWithEqualClasses(self): - TestStatus = self.header1 != self.header3 - self.assertTrue(TestStatus) - - def testHashWithSameClasses(self): - HeaderList = [] - i = 0 - while i < 100: - i += 1 - HeaderList.append( - Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf')) - TestStatus = True - for header in HeaderList: - if header.__hash__ != HeaderList[0].__hash__: - TestStatus = False - self.assertTrue(TestStatus) - - def testHashWithDifferentClasses(self): - HeaderList = [] - i = 0 - while i < 100: - i += 1 - HeaderList.append( - Header(r'КСРФ/'+str(i)+r'-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf')) - HeaderList = [header.__hash__() for header in HeaderList] - TestStatus = True - for header in HeaderList: - if HeaderList.count(header) != 1: - TestStatus = False - self.assertTrue(TestStatus) - - -class DuplicateHeaderTestCase(unittest.TestCase): - def setUp(self): - self.header1 = DuplicateHeader( - r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf') - self.header2 = DuplicateHeader( - r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf') - self.header3 = DuplicateHeader( - r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') - - def testCreateWithCorrectArguments(self): - try: - self.header4 = DuplicateHeader( - r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') - TestStatus = True - except TypeError: - TestStatus = False - self.assertTrue(TestStatus) - - def testCreateWithIncorrectArguments(self): - try: - self.header4 = DuplicateHeader( - r'КСРФ/30-О/2018', r'КСРФ/О', 1488, - 'datetime.date(2018, 9, 27)', - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf') - TestStatus = True - except TypeError: - TestStatus = False - self.assertFalse(TestStatus) - - def testEqWithEqualClasses(self): - TestStatus = self.header1 == self.header2 - self.assertTrue(TestStatus) - - def testEqWithUnequalClasses(self): - TestStatus = self.header1 == self.header3 - self.assertFalse(TestStatus) - - def testNeWithUnequalClasses(self): - TestStatus = self.header1 != self.header2 - self.assertFalse(TestStatus) - - def testNeWithEqualClasses(self): - TestStatus = self.header1 != self.header3 - self.assertTrue(TestStatus) - - def testHashWithSameClasses(self): - HeaderList = [] - i = 0 - while i < 100: - i += 1 - HeaderList.append( - DuplicateHeader(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/357646.pdf')) - TestStatus = True - for header in HeaderList: - if header.__hash__ != HeaderList[0].__hash__: - TestStatus = False - self.assertTrue(TestStatus) - - def testHashWithDifferentClasses(self): - HeaderList = [] - i = 0 - while i < 100: - i += 1 - HeaderList.append( - DuplicateHeader(r'КСРФ/'+str(i)+r'-П/2018', - r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/357646.pdf')) - HeaderList = [header.__hash__() for header in HeaderList] - TestStatus = True - for header in HeaderList: - if HeaderList.count(header) != 1: - TestStatus = False - self.assertTrue(TestStatus) - - -class LinkTestCase(unittest.TestCase): - def setUp(self): - self.link1 = Link( - Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf')) - self.link2 = Link( - Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf')) - self.link3 = Link( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf')) - - def testCreateWithCorrectArguments(self): - try: - self.link4 = Link( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision' - f'/KSRFDecision357727.pdf')) - TestStatus = True - except TypeError: - TestStatus = False - self.assertTrue(TestStatus) - - def testCreateWithIncorrectArguments(self): - try: - self.link4 = Link( - Header(True, r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - 322)) - TestStatus = True - except TypeError: - TestStatus = False - self.assertFalse(TestStatus) - - def testEqWithEqualClasses(self): - TestStatus = self.link1 == self.link2 - self.assertTrue(TestStatus) - - def testEqWithUnequalClasses(self): - TestStatus = self.link1 == self.link3 - self.assertFalse(TestStatus) - - def testNeWithUnequalClasses(self): - TestStatus = self.link1 != self.link2 - self.assertFalse(TestStatus) - - def testNeWithEqualClasses(self): - TestStatus = self.link1 != self.link3 - self.assertTrue(TestStatus) - - def testHashWithSameClasses(self): - LinkList = [] - i = 0 - while i < 100: - i += 1 - LinkList.append( - Link(Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/357646.pdf'))) - TestStatus = True - for link in LinkList: - if link.__hash__ != LinkList[0].__hash__: - TestStatus = False - self.assertTrue(TestStatus) - - def testHashWithDifferentClasses(self): - LinkList = [] - i = 0 - while i < 100: - i += 1 - LinkList.append( - Link(Header(r'КСРФ/'+str(i)+r'-П/2018', - r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/357646.pdf'))) - LinkList = [link.__hash__() for link in LinkList] - TestStatus = True - for link in LinkList: - if LinkList.count(link) != 1: - TestStatus = False - self.assertTrue(TestStatus) - - -class RoughLinkTestCase(unittest.TestCase): - def setUp(self): - self.link1 = RoughLink( - Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), - 'от 1 мая 2018 года № 31-П', 'постановление', 31) - self.link2 = RoughLink( - Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), - 'от 1 мая 2018 года № 31-П', 'постановление', 31) - self.link3 = RoughLink( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), - 'от 2 мая 2018 года № 30-О', 'определение', 30) - - def testCreateWithCorrectArguments(self): - try: - self.link4 = RoughLink( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), - 'от 2 мая 2018 года № 30-О', 'определение', 30) - TestStatus = True - except TypeError: - TestStatus = False - self.assertTrue(TestStatus) - - def testCreateWithIncorrectArguments(self): - try: - self.link4 = RoughLink( - 'Header', - 'от 2 мая 2018 года № 30-О', 'определение', 30) - TestStatus = True - except TypeError: - TestStatus = False - self.assertFalse(TestStatus) - - def testEqWithEqualClasses(self): - TestStatus = self.link1 == self.link2 - self.assertTrue(TestStatus) - - def testEqWithUnequalClasses(self): - TestStatus = self.link1 == self.link3 - self.assertFalse(TestStatus) - - def testNeWithUnequalClasses(self): - TestStatus = self.link1 != self.link2 - self.assertFalse(TestStatus) - - def testNeWithEqualClasses(self): - TestStatus = self.link1 != self.link3 - self.assertTrue(TestStatus) - - def testHashWithSameClasses(self): - LinkList = [] - i = 0 - while i < 100: - i += 1 - LinkList.append(RoughLink( - Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf'), - 'от 3 мая 2018 года № 32-П', 'постановление', 32)) - TestStatus = True - for link in LinkList: - if link.__hash__ != LinkList[0].__hash__: - TestStatus = False - self.assertTrue(TestStatus) - - def testHashWithDifferentClasses(self): - LinkList = [] - i = 0 - while i < 100: - i += 1 - LinkList.append(RoughLink( - Header(r'КСРФ/'+str(i)+r'-П/2018', - r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf'), - 'от 3 мая 2018 года № 32-П', 'постановление', 32)) - LinkList = [link.__hash__() for link in LinkList] - TestStatus = True - for link in LinkList: - if LinkList.count(link) != 1: - TestStatus = False - self.assertTrue(TestStatus) - - -class CleanLinkTestCase(unittest.TestCase): - def setUp(self): - self.link1 = CleanLink( - Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), - Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)'), - 31, (31, 'постановление')) - self.link2 = CleanLink( - Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), - Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)'), - 31, (31, 'постановление')) - self.link3 = CleanLink( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), - Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', - datetime.date(2018, 9, 28), - r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), - 30, (30, 'определение')) - - def testCreateWithCorrectArguments(self): - try: - self.link4 = CleanLink( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), - Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', - datetime.date(2018, 9, 28), - r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), - 30, (30, 'определение')) - TestStatus = True - except TypeError: - TestStatus = False - self.assertTrue(TestStatus) - - def testCreateWithIncorrectArguments(self): - try: - self.link4 = CleanLink( - Header(r'КСРФ/30-О/2018', 228, 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), - Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', - 'datetime.date(2018, 9, 28)', - r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), - '30', (30, 'определение')) - TestStatus = True - except TypeError: - TestStatus = False - self.assertFalse(TestStatus) - - def testEqWithEqualClasses(self): - TestStatus = self.link1 == self.link2 - self.assertTrue(TestStatus) - - def testEqWithUnequalClasses(self): - TestStatus = self.link1 == self.link3 - self.assertFalse(TestStatus) - - def testNeWithUnequalClasses(self): - TestStatus = self.link1 != self.link2 - self.assertFalse(TestStatus) - - def testNeWithEqualClasses(self): - TestStatus = self.link1 != self.link3 - self.assertTrue(TestStatus) - - def testHashWithSameClasses(self): - LinkList = [] - i = 0 - while i < 100: - i += 1 - LinkList.append(CleanLink( - Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf'), - Header(r'КСРФ/33-П/2018', r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf'), - 32, (32, 'постановление'))) - TestStatus = True - for link in LinkList: - if link.__hash__ != LinkList[0].__hash__: - TestStatus = False - self.assertTrue(TestStatus) - - def testHashWithDifferentClasses(self): - LinkList = [] - i = 0 - while i < 100: - i += 1 - LinkList.append(CleanLink( - Header(r'КСРФ/'+str(i)+r'-П/2018', - r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf'), - Header(r'КСРФ/'+str(i+100)+r'-П/2018', - r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf'), - 32, (32, 'постановление'))) - LinkList = [link.__hash__() for link in LinkList] - TestStatus = True - for link in LinkList: - if LinkList.count(link) != 1: - TestStatus = False - self.assertTrue(TestStatus) - - -class HeadersFilterTestCase(unittest.TestCase): - def setUp(self): - self.header1 = HeadersFilter(r'КСРФ/П', datetime.date(2018, 10, 16), - datetime.date(2018, 10, 17)) - self.header2 = HeadersFilter(r'КСРФ/П', datetime.date(2018, 10, 16), - datetime.date(2018, 10, 17)) - self.header3 = HeadersFilter(r'КСРФ/О', datetime.date(2018, 9, 27), - datetime.date(2018, 9, 28)) - - def testCreateWithCorrectArguments(self): - try: - self.header4 = HeadersFilter(r'КСРФ/О', - datetime.date(2018, 9, 27), - datetime.date(2018, 9, 28)) - TestStatus = True - except TypeError: - TestStatus = False - self.assertTrue(TestStatus) - - def testCreateWithIncorrectArguments(self): - try: - self.header4 = HeadersFilter(r'КСРФ/О', - True, - datetime.date(2018, 9, 28)) - TestStatus = True - except TypeError: - TestStatus = False - self.assertFalse(TestStatus) - - def testEqWithEqualClasses(self): - TestStatus = self.header1 == self.header2 - self.assertTrue(TestStatus) - - def testEqWithUnequalClasses(self): - TestStatus = self.header1 == self.header3 - self.assertFalse(TestStatus) - - def testNeWithUnequalClasses(self): - TestStatus = self.header1 != self.header2 - self.assertFalse(TestStatus) - - def testNeWithEqualClasses(self): - TestStatus = self.header1 != self.header3 - self.assertTrue(TestStatus) - - def testHashWithSameClasses(self): - HeaderList = [] - i = 0 - while i < 100: - i += 1 - HeaderList.append(HeadersFilter(r'КСРФ/П', - datetime.date(2018, 10, 16), - datetime.date(2018, 10, 17))) - TestStatus = True - for header in HeaderList: - if header.__hash__ != HeaderList[0].__hash__: - TestStatus = False - self.assertTrue(TestStatus) - - def testHashWithDifferentClasses(self): - HeaderList = [] - i = 0 - while i < 100: - i += 1 - HeaderList.append(HeadersFilter(r'КСРФ/П'+str(i), - datetime.date(i, 10, 16), - datetime.date(i, 10, 17))) - HeaderList = [header.__hash__() for header in HeaderList] - TestStatus = True - for header in HeaderList: - if HeaderList.count(header) != 1: - TestStatus = False - self.assertTrue(TestStatus) - - def testGetFilteredHeadersWithNotEmptyFilter(self): - HeadersDict = {r'КСРФ/31-П/2018': Header( - r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf')} - TestStatus = True - if self.header1.get_filtered_headers(HeadersDict) is None: - TestStatus = False - self.assertTrue(TestStatus) - - def testGetFilteredHeadersWithEmptyFilter(self): - HeadersDict = {r'КСРФ/31-П/2018': Header( - r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf')} - TestStatus = True - self.header4 = HeadersFilter() - if self.header4.get_filtered_headers(HeadersDict) is None: - TestStatus = False - self.assertTrue(TestStatus) - - -class GraphNodesFilterTestCase(unittest.TestCase): - def setUp(self): - self.node1 = GraphNodesFilter(r'КСРФ/П', datetime.date(2018, 10, 16), - datetime.date(2018, 10, 17), - (0, 31), (32, 60)) - self.node2 = GraphNodesFilter(r'КСРФ/П', datetime.date(2018, 10, 16), - datetime.date(2018, 10, 17), - (0, 31), (32, 60)) - self.node3 = GraphNodesFilter(r'КСРФ/О', datetime.date(2018, 9, 27), - datetime.date(2018, 9, 28), - (0, 30), (31, 60)) - - def testCreateWithCorrectArguments(self): - try: - self.node4 = GraphNodesFilter(r'КСРФ/О', - datetime.date(2018, 9, 27), - datetime.date(2018, 9, 28), - (0, 30), (31, 60)) - TestStatus = True - except TypeError: - TestStatus = False - self.assertTrue(TestStatus) - - def testCreateWithIncorrectArguments(self): - try: - self.node4 = GraphNodesFilter(r'КСРФ/О', - datetime.date(2018, 9, 27), - datetime.date(2018, 9, 28), - (0, 'lol'), ('proverka', 60)) - TestStatus = True - except TypeError: - TestStatus = False - self.assertFalse(TestStatus) - - def testEqWithEqualClasses(self): - TestStatus = self.node1 == self.node2 - self.assertTrue(TestStatus) - - def testEqWithUnequalClasses(self): - TestStatus = self.node1 == self.node3 - self.assertFalse(TestStatus) - - def testNeWithUnequalClasses(self): - TestStatus = self.node1 != self.node2 - self.assertFalse(TestStatus) - - def testNeWithEqualClasses(self): - TestStatus = self.node1 != self.node3 - self.assertTrue(TestStatus) - - def testHashWithSameClasses(self): - NodeList = [] - i = 0 - while i < 100: - i += 1 - NodeList.append(GraphNodesFilter(r'КСРФ/П', - datetime.date(2018, 10, 16), - datetime.date(2018, 10, 17), - (0, 32), (33, 60))) - TestStatus = True - for node in NodeList: - if node.__hash__ != NodeList[0].__hash__: - TestStatus = False - self.assertTrue(TestStatus) - - def testHashWithDifferentClasses(self): - NodeList = [] - i = 0 - while i < 100: - i += 1 - NodeList.append(GraphNodesFilter(r'КСРФ/П'+str(i), - datetime.date(i, 10, 16), - datetime.date(i, 10, 17), - (0, 32), (33, 60))) - NodeList = [node.__hash__() for node in NodeList] - TestStatus = True - for node in NodeList: - if NodeList.count(node) != 1: - TestStatus = False - self.assertTrue(TestStatus) - - -class GraphEdgesFilterTestCase(unittest.TestCase): - def setUp(self): - self.edge1 = GraphEdgesFilter( - HeadersFilter(r'КСРФ/П', datetime.date(2018, 10, 16), - datetime.date(2018, 10, 17)), - HeadersFilter(r'КСРФ/П-О', datetime.date(2018, 10, 17), - datetime.date(2018, 10, 18)), - (0, 31)) - self.edge2 = GraphEdgesFilter( - HeadersFilter(r'КСРФ/П', datetime.date(2018, 10, 16), - datetime.date(2018, 10, 17)), - HeadersFilter(r'КСРФ/П-О', datetime.date(2018, 10, 17), - datetime.date(2018, 10, 18)), - (0, 31)) - self.edge3 = GraphEdgesFilter( - HeadersFilter(r'КСРФ/О', datetime.date(2018, 9, 27), - datetime.date(2018, 9, 28)), - HeadersFilter(r'КСРФ/О-О', datetime.date(2018, 9, 28), - datetime.date(2018, 9, 29)), - (0, 30)) - - def testCreateWithCorrectArguments(self): - try: - self.edge4 = GraphEdgesFilter( - HeadersFilter(r'КСРФ/О', datetime.date(2018, 9, 27), - datetime.date(2018, 9, 28)), - HeadersFilter(r'КСРФ/О-О', datetime.date(2018, 9, 28), - datetime.date(2018, 9, 29)), - (0, 30)) - TestStatus = True - except TypeError: - TestStatus = False - self.assertTrue(TestStatus) - - def testCreateWithIncorrectArguments(self): - try: - self.edge4 = GraphEdgesFilter( - HeadersFilter(r'КСРФ/О', datetime.date(2018, 9, 27), - datetime.date(2018, 9, 28)), - 'HeadersFilter', - (0, 30)) - TestStatus = True - except TypeError: - TestStatus = False - self.assertFalse(TestStatus) - - def testEqWithEqualClasses(self): - TestStatus = self.edge1 == self.edge2 - self.assertTrue(TestStatus) - - def testEqWithUnequalClasses(self): - TestStatus = self.edge1 == self.edge3 - self.assertFalse(TestStatus) - - def testNeWithUnequalClasses(self): - TestStatus = self.edge1 != self.edge2 - self.assertFalse(TestStatus) - - def testNeWithEqualClasses(self): - TestStatus = self.edge1 != self.edge3 - self.assertTrue(TestStatus) - - def testHashWithSameClasses(self): - EdgeList = [] - i = 0 - while i < 100: - i += 1 - EdgeList.append(GraphEdgesFilter( - HeadersFilter(r'КСРФ/П', datetime.date(2018, 10, 16), - datetime.date(2018, 10, 17)), - HeadersFilter(r'КСРФ/П-О', datetime.date(2018, 10, 17), - datetime.date(2018, 10, 18)), - (0, 32))) - TestStatus = True - for edge in EdgeList: - if edge.__hash__ != EdgeList[0].__hash__: - TestStatus = False - self.assertTrue(TestStatus) - - def testHashWithDifferentClasses(self): - EdgeList = [] - i = 0 - while i < 100: - i += 1 - EdgeList.append(GraphEdgesFilter( - HeadersFilter(r'КСРФ/П', datetime.date(i, 10, 16), - datetime.date(i, 10, 17)), - HeadersFilter(r'КСРФ/П-О', datetime.date(i, 10, 17), - datetime.date(i, 10, 18)), - (0, i))) - EdgeList = [edge.__hash__() for edge in EdgeList] - TestStatus = True - for edge in EdgeList: - if EdgeList.count(edge) != 1: - TestStatus = False - self.assertTrue(TestStatus) - - def testGetFilteredEdgesWithNotEmptyFilter(self): - Edges = [CleanLink( - Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), - Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)'), - 31, (31, 'постановление')), - CleanLink( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), - Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', - datetime.date(2018, 9, 28), - r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), - 30, (30, 'определение'))] - TestStatus = True - if self.edge1.get_filtered_edges(Edges) is None: - TestStatus = False - self.assertTrue(TestStatus) - - def testGetFilteredEdgesWithEmptyFilter(self): - Edges = [CleanLink( - Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), - Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)'), - 31, (31, 'постановление')), - CleanLink( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), - Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', - datetime.date(2018, 9, 28), - r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), - 30, (30, 'определение'))] - TestStatus = True - self.edge4 = GraphEdgesFilter() - if self.edge4.get_filtered_edges(Edges) is None: - TestStatus = False - self.assertTrue(TestStatus) - - -class LinkGraphTestCase(unittest.TestCase): - def setUp(self): - self.graph1 = LinkGraph() - self.graph1.add_node( - Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)')) - self.graph1.add_node( - Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)')) - self.graph1.add_edge( - CleanLink( - Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), - Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)'), - 31, (31, 'постановление'))) - self.graph2 = LinkGraph() - self.graph2.add_node( - Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)')) - self.graph2.add_node( - Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)')) - self.graph2.add_edge( - CleanLink( - Header(r'КСРФ/31-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf)'), - Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/KSRFDecision357647.pdf)'), - 31, (31, 'постановление'))) - self.graph3 = LinkGraph() - self.graph3.add_node( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf')) - self.graph3.add_node( - Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', - datetime.date(2018, 9, 28), - r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf')) - self.graph3.add_edge( - CleanLink( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/KSRFDecision357727.pdf'), - Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', - datetime.date(2018, 9, 28), - r'http://doc.ksrf.ru/decision/KSRFDecision357728.pdf'), - 30, (30, 'определение'))) - - def testCreateWithCorrectArguments(self): - try: - self.graph4 = LinkGraph() - self.graph4.add_node( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/357727.pdf')) - self.graph4.add_node( - Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', - datetime.date(2018, 9, 28), - r'http://doc.ksrf.ru/decision/357728.pdf')) - self.graph4.add_edge( - CleanLink( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/357727.pdf'), - Header(r'КСРФ/31-О/2018', r'КСРФ/О', 'uvidimsya', - datetime.date(2018, 9, 28), - r'http://doc.ksrf.ru/decision/357728.pdf'), - 30, (30, 'определение'))) - TestStatus = True - except TypeError: - TestStatus = False - self.assertTrue(TestStatus) - - def testCreateWithIncorrectArguments(self): - try: - self.graph4 = LinkGraph() - self.graph4.add_node( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/357727.pdf')) - self.graph4.add_node( - Header(r'КСРФ/31-О/2018', r'КСРФ/О', 14, - datetime.date(2018, 9, 28), - r'http://doc.ksrf.ru/decision/357728.pdf')) - self.graph4.add_edge( - CleanLink( - Header(r'КСРФ/30-О/2018', r'КСРФ/О', 'zdarova', - datetime.date(2018, 9, 27), - r'http://doc.ksrf.ru/decision/357727.pdf'), - Header(r'КСРФ/31-О/2018', False, 'uvidimsya', - datetime.date(2018, 9, 28), - r'http://doc.ksrf.ru/decision/357728.pdf'), - 30, (30, 322))) - TestStatus = True - except TypeError: - TestStatus = False - self.assertFalse(TestStatus) - - def testEqWithEqualClasses(self): - TestStatus = self.graph1 == self.graph2 - self.assertTrue(TestStatus) - - def testEqWithUnequalClasses(self): - TestStatus = self.graph1 == self.graph3 - self.assertFalse(TestStatus) - - def testNeWithUnequalClasses(self): - TestStatus = self.graph1 != self.graph2 - self.assertFalse(TestStatus) - - def testNeWithEqualClasses(self): - TestStatus = self.graph1 != self.graph3 - self.assertTrue(TestStatus) - - def testHashWithSameClasses(self): - GraphList = [] - i = 0 - while i < 100: - i += 1 - self.graph = LinkGraph() - self.graph.add_node( - Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/357646.pdf')) - self.graph.add_node( - Header(r'КСРФ/33-П/2018', r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/357647.pdf')) - self.graph.add_edge( - CleanLink( - Header(r'КСРФ/32-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/357646.pdf'), - Header(r'КСРФ/33-П/2018', r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/357647.pdf'), - 32, (32, 'постановление'))) - GraphList.append(self.graph) - TestStatus = True - for graph in GraphList: - if graph.__hash__ != GraphList[0].__hash__: - TestStatus = False - self.assertTrue(TestStatus) - - def testHashWithDifferentClasses(self): - GraphList = [] - i = 0 - while i < 100: - i += 1 - self.graph = LinkGraph() - self.graph.add_node( - Header(r'КСРФ/'+str(i)+r'-П/2018', - r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/357646.pdf')) - self.graph.add_node( - Header(r'КСРФ/'+str(i+1)+r'-П/2018', - r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/357647.pdf')) - self.graph.add_edge( - CleanLink( - Header(r'КСРФ/'+str(i)+r'-П/2018', r'КСРФ/П', 'privet', - datetime.date(2018, 10, 16), - r'http://doc.ksrf.ru/decision/357646.pdf'), - Header(r'КСРФ/'+str(i+1)+r'-П/2018', r'КСРФ/П', 'poka', - datetime.date(2018, 10, 17), - r'http://doc.ksrf.ru/decision/357647.pdf'), - 32, (32, 'постановление'))) - GraphList.append(self.graph) - HashList = [] - for graph in GraphList: - HashList.append(self.graph.__hash__()) - TestStatus = True - for graph in GraphList: - if GraphList.count(graph) != 1: - TestStatus = False - self.assertTrue(TestStatus) - - -suite = unittest.TestLoader().loadTestsFromTestCase(DocumentHeaderTestCase) -unittest.TextTestRunner(verbosity=2).run(suite) -suite = unittest.TestLoader().loadTestsFromTestCase(HeaderTestCase) -unittest.TextTestRunner(verbosity=2).run(suite) -suite = unittest.TestLoader().loadTestsFromTestCase(DuplicateHeaderTestCase) -unittest.TextTestRunner(verbosity=2).run(suite) -suite = unittest.TestLoader().loadTestsFromTestCase(LinkTestCase) -unittest.TextTestRunner(verbosity=2).run(suite) -suite = unittest.TestLoader().loadTestsFromTestCase(RoughLinkTestCase) -unittest.TextTestRunner(verbosity=2).run(suite) -suite = unittest.TestLoader().loadTestsFromTestCase(CleanLinkTestCase) -unittest.TextTestRunner(verbosity=2).run(suite) -suite = unittest.TestLoader().loadTestsFromTestCase(HeadersFilterTestCase) -unittest.TextTestRunner(verbosity=2).run(suite) -suite = unittest.TestLoader().loadTestsFromTestCase(GraphNodesFilterTestCase) -unittest.TextTestRunner(verbosity=2).run(suite) -suite = unittest.TestLoader().loadTestsFromTestCase(GraphEdgesFilterTestCase) -unittest.TextTestRunner(verbosity=2).run(suite) -suite = unittest.TestLoader().loadTestsFromTestCase(LinkGraphTestCase) -unittest.TextTestRunner(verbosity=2).run(suite) - -if __name__ == '__main__': - unittest.main() diff --git a/link_analysis/testrough.py b/link_analysis/testrough.py deleted file mode 100644 index abc6ccf..0000000 --- a/link_analysis/testrough.py +++ /dev/null @@ -1,104 +0,0 @@ -import datetime -import collections -import unittest -from models import DocumentHeader, Header, DuplicateHeader, Link, RoughLink -from models import CleanLink, HeadersFilter, GraphNodesFilter, GraphEdgesFilter -from models import LinkGraph -from rough_analysis import get_rough_links - - -class RoughAnalysisTestCase(unittest.TestCase): - def testRough1(self): - header1 = Header( - 'text1', 'txt', 'text1', - datetime.date(2018, 10, 24), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', - r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test1.txt') - RoughList = ['от 31 8 октября 23 2007 42 года № 420-О', - 'от 31 8 октября 23 2007 42 года № 13 421-П', - 'от 31 8 октября 23 2007 42 года № 422-Р', - 'от 31 8 октября 23 2007 42 года № 423-О-П'] - TestStatus = True - BodyList = [] - for roughlink in get_rough_links(header1): - BodyList.append(roughlink.body) - if BodyList != RoughList: - TestStatus = False - self.assertTrue(TestStatus) - - def testRough2(self): - header1 = Header( - 'text2', 'txt', 'text2', - datetime.date(2018, 10, 24), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', - r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test2.txt') - RoughList = ['от 322 16 228 мая 007 1998 1488 года № 1707 80-Л-О-Л-З-А-А-Л-Ь-Я-Н-С'] - TestStatus = True - BodyList = [] - for roughlink in get_rough_links(header1): - BodyList.append(roughlink.body) - if BodyList != RoughList: - TestStatus = False - self.assertTrue(TestStatus) - - def testRough3(self): - header1 = Header( - 'text3', 'txt', 'text3', - datetime.date(2018, 10, 24), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', - r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test3.txt') - RoughList = ['от 4444 44444444 4444 28 4221 декабря 2111 2019 года № 1111111-J-P-E'] - TestStatus = True - BodyList = [] - for roughlink in get_rough_links(header1): - BodyList.append(roughlink.body) - if BodyList != RoughList: - TestStatus = False - self.assertTrue(TestStatus) - - def testRough4(self): - header1 = Header( - 'text4', 'txt', 'text4', - datetime.date(2018, 10, 24), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', - r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test4.txt') - RoughList = ['от 23 2 февраля 222 2005 133 года № 18-Г-О', - 'от 23 2 февраля 222 2005 133 года № 13 19-Ю-S', - 'от 23 2 февраля 222 2005 133 года № 20-R', - 'от 23 2 февраля 222 2005 133 года № 21-U-F-C', - 'от 28 марта 2014 года № 300-О-П'] - TestStatus = True - BodyList = [] - for roughlink in get_rough_links(header1): - BodyList.append(roughlink.body) - if BodyList != RoughList: - TestStatus = False - self.assertTrue(TestStatus) - - def testRough5(self): - header1 = Header( - 'text5', 'txt', 'text5', - datetime.date(2018, 10, 24), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', - r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test5.txt') - RoughList = ['от 24 декабря 1992 года № 123-А'] - TestStatus = True - BodyList = [] - for roughlink in get_rough_links(header1): - BodyList.append(roughlink.body) - if BodyList != RoughList: - TestStatus = False - self.assertTrue(TestStatus) - - -suite = unittest.TestLoader().loadTestsFromTestCase(RoughAnalysisTestCase) -unittest.TextTestRunner(verbosity=2).run(suite) -''' -header1 = Header( - 'text5', 'txt', 'text5', - datetime.date(2018, 10, 24), - r'http://doc.ksrf.ru/decision/KSRFDecision357646.pdf', - r'C:\\Vs Code Projects\\Python Projects\\link_analysis-project\\Decision files\\test5.txt') -for roughlink in get_rough_links(header1): - print(roughlink.body) -'''