def test_can_seek_to_top(self):
     s = FromListFileField("test",TMP_TEST_LIST, {"method":"sequential"})
     line = s.getOneLine()
     self.assertEqual("line0", line)
     line = s.getOneLine()
     self.assertEqual("line1", line)
     line = s.getOneLine()
     self.assertEqual("line0", line)
    def test_get_line_random(self):
        s = FromListFileField("test",TMP_TEST_LIST, {"method":"random"})
        first_match_count = 0
        for i in range(100):
            line = s.getOneLine()
            if line == 'line0':
                first_match_count += 1

        second_match_count = 0
        for i in range(100):
            line = s.getOneLine()
            if line == 'line0':
                second_match_count += 1

        self.assertFalse(first_match_count == second_match_count)
        self.assertGreater(first_match_count,0)
    def test_get_line_ratio_20_80(self):
        list_file = open(TMP_TEST_LIST2,"w")
        for i in [0,0,1,1,1,1,1,1,1,1]:
            list_file.write(str(i)+"\n")
        list_file.close()

        s = FromListFileField("test", TMP_TEST_LIST2, {"method":"ratio", "ratio":"20,80"})
        match_count = 0
        for i in range(10):
            line = s.getOneLine()
            if line == '0':
                match_count += 1

        self.assertEqual(2, match_count)