예제 #1
0
 def test_greater(self):
     correct = {'right': ['2.7', '3.0', '3.1'],
                'wrong': ['0.9', '1.0', '1.8', '2.0', '2.6']}
                
     r = parse_python_version('>2.7', self.VERSIONS)
     self.assertEquals(r, correct)
                           
     r = parse_python_version('2.7+', self.VERSIONS)
     self.assertEquals(r, correct)
예제 #2
0
    def test_single(self):
        r = parse_python_version('2.6', self.VERSIONS)
        self.assertEquals(r, {'right': ['2.6'],
                              'wrong': ['0.9', '1.0', '1.8', '2.0',
                                        '2.7', '3.0', '3.1']})

        r = parse_python_version('0.9', self.VERSIONS)
        self.assertEquals(r, {'right': ['0.9'],
                              'wrong': ['1.0', '1.8', '2.0', '2.6',
                                        '2.7', '3.0', '3.1']})
예제 #3
0
    def test_greater(self):
        correct = {
            'right': ['2.7', '3.0', '3.1'],
            'wrong': ['0.9', '1.0', '1.8', '2.0', '2.6']
        }

        r = parse_python_version('>2.7', self.VERSIONS)
        self.assertEquals(r, correct)

        r = parse_python_version('2.7+', self.VERSIONS)
        self.assertEquals(r, correct)
예제 #4
0
    def test_single(self):
        r = parse_python_version('2.6', self.VERSIONS)
        self.assertEquals(
            r, {
                'right': ['2.6'],
                'wrong': ['0.9', '1.0', '1.8', '2.0', '2.7', '3.0', '3.1']
            })

        r = parse_python_version('0.9', self.VERSIONS)
        self.assertEquals(
            r, {
                'right': ['0.9'],
                'wrong': ['1.0', '1.8', '2.0', '2.6', '2.7', '3.0', '3.1']
            })
예제 #5
0
    def split_choices(self):
        ret = utils.parse_python_version(self.choices_raw, self.VERSIONS)
        rand = random.random()
        wrong_choice_count = 2  # the number of wrong choices to render

        text = self.md(self.text)
        right = ret['right']
        wrong = ret['wrong']

        number_of_right = len(right)
        number_of_wrong = len(wrong)

        # one random right answer
        single_right = right[int(number_of_right * random.random())]

        # a list random wrong answers (makes sure none are duplicated)
        choices_wrong = []
        while len(choices_wrong) < wrong_choice_count:
            index = int(number_of_wrong * random.random())
            rand_wrong = wrong[index]
            if not rand_wrong in choices_wrong:
                choices_wrong.append(rand_wrong)

        return {'text': text, 'right': single_right, 'wrong': choices_wrong}
예제 #6
0
    def split_choices(self):
        ret = utils.parse_python_version(self.choices_raw, self.VERSIONS)
        rand = random.random()
        wrong_choice_count = 2  # the number of wrong choices to render

        text = self.md(self.text)
        right = ret["right"]
        wrong = ret["wrong"]

        number_of_right = len(right)
        number_of_wrong = len(wrong)

        # one random right answer
        single_right = right[int(number_of_right * random.random())]

        # a list random wrong answers (makes sure none are duplicated)
        choices_wrong = []
        while len(choices_wrong) < wrong_choice_count:
            index = int(number_of_wrong * random.random())
            rand_wrong = wrong[index]
            if not rand_wrong in choices_wrong:
                choices_wrong.append(rand_wrong)

        return {"text": text, "right": single_right, "wrong": choices_wrong}