def test_calculate_top_htmls_complex(self): """Calculate top htmls, more complex. The page limit will cut the list in a page that has the same score of others, so let's include them all. """ ps = PagesSelector() config.imageconf['page_limit'] = 4 ps.calculate() should_pages = [ ('dir1', 'arch1', 8), ('dir2', 'arch2', 7), ('dir3', 'arch3', 5), ('dir4', 'arch4', 4), ('dir5', 'arch5', 4), ] self.assertEqual(ps.top_pages, should_pages) # check info is stored ok in disk should_stored = [ config.SEPARADOR_COLUMNAS.join(map(str, p)) + '\n' for p in should_pages ] with open(config.PAG_ELEGIDAS, 'rt') as fh: lines = fh.readlines() self.assertEqual(lines, should_stored)
def test_calculate_top_htmls_simple(self): """Calculate top htmls, simple version.""" ps = PagesSelector() config.imageconf['page_limit'] = 2 ps.calculate() should_pages = [ ('dir1', 'arch1', 8), ('dir2', 'arch2', 7), ] self.assertEqual(ps.top_pages, should_pages) # check info is stored ok in disk should_stored = [config.SEPARADOR_COLUMNAS.join(map(str, p)) + '\n' for p in should_pages] with open(config.PAG_ELEGIDAS, 'rt') as fh: lines = fh.readlines() self.assertEqual(lines, should_stored)
def test_sameinfo_previousequal(self): """Check 'same info than before', previous info there and equal.""" # make one pass just to write the 'choosen pages' file ps = PagesSelector() ps.calculate() # go again, the info will be the same ps = PagesSelector() ps.calculate() self.assertTrue(ps.same_info_through_runs)
def test_calculate_top_htmls_simple(self): """Calculate top htmls, simple version.""" ps = PagesSelector() config.imageconf['page_limit'] = 2 ps.calculate() should_pages = [ ('dir1', 'arch1', 8), ('dir2', 'arch2', 7), ] self.assertEqual(ps.top_pages, should_pages) # check info is stored ok in disk should_stored = [ config.SEPARADOR_COLUMNAS.join(map(str, p)) + '\n' for p in should_pages ] with open(config.PAG_ELEGIDAS, 'rt') as fh: lines = fh.readlines() self.assertEqual(lines, should_stored)
def test_sameinfo_previousdifferent(self): """Check 'same info than before', previous info there but different.""" # make one pass just to write the 'choosen pages' file ps = PagesSelector() ps.calculate() # get that file and change it slightly with open(config.PAG_ELEGIDAS, 'rt') as fh: lines = fh.readlines() with open(config.PAG_ELEGIDAS, 'wt') as fh: fh.writelines(lines[:-1]) # go again, the info will be the same ps = PagesSelector() ps.calculate() self.assertFalse(ps.same_info_through_runs)
def test_calculate_top_htmls_complex(self): """Calculate top htmls, more complex. The page limit will cut the list in a page that has the same score of others, so let's include them all. """ ps = PagesSelector() config.imageconf['page_limit'] = 4 ps.calculate() should_pages = [ ('dir1', 'arch1', 8), ('dir2', 'arch2', 7), ('dir3', 'arch3', 5), ('dir4', 'arch4', 4), ('dir5', 'arch5', 4), ] self.assertEqual(ps.top_pages, should_pages) # check info is stored ok in disk should_stored = [config.SEPARADOR_COLUMNAS.join(map(str, p)) + '\n' for p in should_pages] with open(config.PAG_ELEGIDAS, 'rt') as fh: lines = fh.readlines() self.assertEqual(lines, should_stored)
def test_sameinfo_noprevious(self): """Check 'same info than before', no previous info.""" os.remove(config.PAG_ELEGIDAS) ps = PagesSelector() ps.calculate() self.assertFalse(ps.same_info_through_runs)
def test_assert_attributes_validity(self): """Need to first calculate for attribs be valid.""" ps = PagesSelector() # instantiate, and don't calculate self.assertRaises(ValueError, getattr, ps, 'top_pages') self.assertRaises(ValueError, getattr, ps, 'same_info_through_runs')