Beispiel #1
0
 def populate_with_searches(self):
     print("Populating from search:")
     for keyword in config.START_KEYWORDS:
         page = Page()
         page.url = "https://www.google.com.ua/search?q={}+articles".format(
             keyword)
         page.save()
         self.put(page.url)
Beispiel #2
0
 def test_026(self):
     """ Document [] setter """
     document = Document("test.txt")
     page = Page(text='hello world')
     document[0] = page
     self.assertEqual(document[0].text, "hello world")
     os.remove("test1.txt")    
Beispiel #3
0
 def test_026(self):
     """ Page overridden += : words is non-None """
     page = Page(text="hello")
     self.assertEqual(len(page), 1)
     page += "world"
     self.assertEqual(page.text, "hello world")
     self.assertEqual(len(page), 2)
Beispiel #4
0
 def test_028(self):
     """ Document [] setter - not an int index """
     document = Document("test.txt")
     page = Page(text='hello world')
     with pytest.raises(TypeError):
         document['abc'] = page
     os.remove("test1.txt")
Beispiel #5
0
 def xtest_bugs(self):
     """ Page store/load - unicode - cryllic """
     page = Page(text="Й й")
     page.store('tmp.txt')
     page._words = None
     page.load('tmp.txt')
     os.remove("tmp.txt")
     self.assertEqual(towords(page.words), ["Й", "й"])
Beispiel #6
0
 def test_032(self):
     """ Page store/load """
     page = Page(text="hello world, goodbye")
     page.store('tmp.txt')
     page._words = None
     page.load('tmp.txt')
     os.remove("tmp.txt")
     self.assertEqual(towords(page.words), ["hello", "world", "goodbye"])
Beispiel #7
0
 def test_005(self):
     """ Page constructor - path keyword parameter """
     page = Page(text="foo")
     self.assertEqual(page.path, None)
     self.assertEqual(page.text, 'foo')
     self.assertEqual(towords(page.words), ["foo"])
Beispiel #8
0
 def test_004(self):
     """ Page constructor - path keyword parameter """
     page = Page(path="test.txt")
     self.assertEqual(page.path, "test.txt")
     self.assertEqual(page.text, None)
     self.assertEqual(page.words, None)
Beispiel #9
0
 def test_003(self):
     """ Page constructor - path and text parameter """
     page = Page("test.txt", "foo")
     self.assertEqual(page.path, "test.txt")
     self.assertEqual(page.text, "foo")
     self.assertEqual(towords(page.words), ["foo"])
Beispiel #10
0
 def test_027(self):
     """ Page words getter  """
     page = Page(text="hello world")
     self.assertEqual(towords(page.words), ['hello', 'world'])
Beispiel #11
0
 def test_012(self):
     """ Page path setter - None """
     page = Page()
     page.path = None
     self.assertEqual(page.path, None)
Beispiel #12
0
 def test_010(self):
     """ Page path setter - not a string """
     page = Page()
     with pytest.raises(TypeError):
         page.path = 12
Beispiel #13
0
 def test_008(self):
     """ Page constructor - path is not a file """
     with pytest.raises(FileNotFoundError):
         page = Page(path='nonexist.txt')
Beispiel #14
0
 def test_033(self):
     """ Page store/load - unicode - latin """
     page = Page(text="hāllo world, goodbye")
     page.store('tmp.txt')
     page._words = None
     page.load('tmp.txt')
     self.assertEqual(towords(page.words), ["hāllo", "world", "goodbye"])
     os.remove("tmp.txt")
     Page.ROMAN = True
     page = Page(text="québec")
     page.store('tmp.txt')
     page._words = None
     page.load('tmp.txt')
     Page.ROMAN = False
     self.assertEqual(towords(page.words), ["quebec"])
     os.remove("tmp.txt")
Beispiel #15
0
 def test_031(self):
     """ Page number """
     page = Page("test.txt")
     self.assertEqual(page.pageno, None)
     page = Page("test.txt", pageno=2)
     self.assertEqual(page.pageno, 2)
Beispiel #16
0
 def test_030(self):
     """ Page size getter - text  """
     page = Page(text="hello world")
     self.assertEqual(page.size, 11)
Beispiel #17
0
 def test_029(self):
     """ Page size getter - no text  """
     page = Page(text="")
     self.assertEqual(page.size, 0)
Beispiel #18
0
 def test_028(self):
     """ Page size getter - no page  """
     page = Page()
     self.assertEqual(page.size, 0)
Beispiel #19
0
 def test_006(self):
     """ Page constructor - path is not a string """
     with pytest.raises(TypeError):
         page = Page(path=12)
Beispiel #20
0
 def test_034(self):
     """ Page - Bag of Words """
     page = Page(text="zoo castle zoo bird zoo bird")
     self.assertEqual(page.bagOfWords, {'zoo': 3, 'castle': 1, 'bird': 2})
Beispiel #21
0
 def test_007(self):
     """ Page constructor - text is not a string """
     with pytest.raises(TypeError):
         page = Page(text=12)
Beispiel #22
0
 def test_035(self):
     """ Page - Word Counts """
     page = Page(text="zoo castle zoo bird zoo bird")
     self.assertEqual(page.freqDist, [('zoo', 3), ('bird', 2),
                                      ('castle', 1)])
Beispiel #23
0
 def test_009(self):
     """ Page path getter/setter """
     page = Page()
     self.assertEqual(page.path, None)
     page.path = "test.txt"
     self.assertEqual(page.path, 'test.txt')
Beispiel #24
0
 def test_014(self):
     """ Page text setter - not a string """
     page = Page()
     with pytest.raises(TypeError):
         page.text = 12
Beispiel #25
0
 def test_011(self):
     """ Page path setter - not a valid file """
     page = Page()
     with pytest.raises(FileNotFoundError):
         page.path = 'nonexist.txt'
Beispiel #26
0
 def test_001(self):
     """ Page constructor - no parameters """
     page = Page()
     self.assertEqual(page.path, None)
     self.assertEqual(page.text, None)
     self.assertEqual(page.words, None)
Beispiel #27
0
 def test_013(self):
     """ Page text getter/setter """
     page = Page()
     self.assertEqual(page.text, None)
     page.text = "hello world"
     self.assertEqual(page.text, 'hello world')
Beispiel #28
0
 def test_025(self):
     """ Page overridden += : text is non-None, self._text is non-None """
     page = Page(text="hello")
     page += "world"
     self.assertEqual(page.text, "hello world")
Beispiel #29
0
 def test_036(self):
     """ Page - Term Frequency """
     page = Page(text="zoo castle zoo bird zoo bird zoo bird")
     self.assertEqual(page.termFreq, [('zoo', 0.5), ('bird', 0.375),
                                      ('castle', 0.125)])
Beispiel #30
0
 def test_022(self):
     """ Page overridden += : text is None, self._text is None """
     page = Page()
     page += None
     self.assertEqual(page.text, None)