Beispiel #1
0
    def _simplify_data(self, key, value, options, param_type):
        if param_type == 'SET-type':
            #print("adding isubcase=%s key=%r value=%r options=%r "
            #"param_type=%r" % (self.id, key, value, options, param_type))
            values2 = expand_thru_case_control(value)
            assert isinstance(values2, list), type(values2)
            if isinstance(options, list):
                msg = 'invalid type for options=%s value; expected an integer; got a list' % key
                raise TypeError(msg)
            options = int(options)
            return (key, values2, options)

        elif param_type == 'CSV-type':
            #print("adding isubcase=%s key=%r value=|%s| options=|%s| "
            #      "param_type=%s" %(self.id, key, value, options, param_type))
            if value.isdigit():  # PARAM,DBFIXED,-1
                value = value
        #elif param_type == 'OBJ-type':
        ##self.params[value.type] = value
        #return value.type,
        elif param_type == 'OBJ-type':
            raise RuntimeError(
                'this function should never be called with an OBJ-type...')
        else:
            #if 0:
            #a = 'key=%r' % key
            #b = 'value=%r' % value
            #c = 'options=%r' % options
            #d = 'param_type=%r' % param_type
            #print("_adding isubcase=%s %-18s %-12s %-12s %-12s" %(self.id, a, b, c, d))
            if isinstance(value, integer_types) or value is None:
                pass
            elif isinstance(value, (list, ndarray)):  # new???
                msg = 'invalid type for key=%s value; expected an integer; got a list' % key
                raise TypeError(msg)
            elif value.isdigit():  # STRESS = ALL
                value = value
            #else: pass
        return key, value, options
Beispiel #2
0
 def test_expand_floats(self):
     """tests expand"""
     values1 = expand_thru_case_control(['500. 2000.'])
     values2 = expand_thru_case_control([500., 2000.])
     assert values1 == [500., 2000.], values1
     assert values2 == [500., 2000.], values2
Beispiel #3
0
    def test_expand_thru(self):
        """tests expand_thru"""
        values1 = expand_thru_case_control(
            ['include 14,15, include 18 thru 24'])
        assert values1 == [14, 15, 18, 19, 20, 21, 22, 23, 24], values1

        values1 = expand_thru_case_control(
            ['include 10 thru 17 except 14 thru 15, include 43 thru 45'])
        assert values1 == [10, 11, 12, 13, 16, 17, 43, 44, 45], values1

        values1 = expand_thru_case_control(
            ['1', '2', '21', 'THRU', '25', '31', 'THRU', '37'])
        values2 = expand_thru_case_control(
            ['1', '2', '21', 'THRU', '25', '31', 'THRU', '37 '])
        values3 = expand_thru_case_control(
            [1, 2, 21, 'THRU', 25, 31, 'THRU', 37])
        assert values1 == [
            1, 2, 21, 22, 23, 24, 25, 31, 32, 33, 34, 35, 36, 37
        ], values1
        assert values2 == [
            1, 2, 21, 22, 23, 24, 25, 31, 32, 33, 34, 35, 36, 37
        ], values2
        assert values3 == [
            1, 2, 21, 22, 23, 24, 25, 31, 32, 33, 34, 35, 36, 37
        ], values3

        values1 = expand_thru_case_control(['1 , 9 THRU 12 , 1040'])
        values2 = expand_thru_case_control(['1 , 9 THRU 12 , 1040'])
        assert values1 == [1, 9, 10, 11, 12, 1040], values1
        assert values2 == [1, 9, 10, 11, 12, 1040], values2

        values1 = expand_thru(['1', 'THRU', '10'])
        values2 = expand_thru_case_control(['1', 'THRU', '10'])
        values3 = expand_thru_case_control(['1 THRU 10'])
        values4 = expand_thru_case_control(['1 THRU 10 '])
        assert values1 == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], values1
        assert values2 == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], values2
        assert values3 == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], values3
        assert values4 == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], values4

        values1 = expand_thru(['1', 'thru', '10'])
        values2 = expand_thru_case_control(['1', 'thru', '10'])
        values3 = expand_thru_case_control(['1 thru 10'])
        values4 = expand_thru_case_control(['1, thru, 10'])
        assert values1 == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], values1
        assert values2 == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], values2
        assert values3 == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], values3
        assert values4 == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], values4

        values1 = expand_thru([1, 2, 3, 4, 5])
        values2 = expand_thru_case_control([1, 2, 3, 4, 5])
        values3 = expand_thru_case_control(['1, 2, 3, 4, 5'])
        values4 = expand_thru_case_control(['1 2 3 4 5'])
        values5 = expand_thru_case_control(['1 2 3 4 5 '])
        assert values1 == [1, 2, 3, 4, 5], values1
        assert values2 == [1, 2, 3, 4, 5], values2
        assert values3 == [1, 2, 3, 4, 5], values3
        assert values4 == [1, 2, 3, 4, 5], values4
        assert values5 == [1, 2, 3, 4, 5], values5

        values1 = expand_thru_by(['1', 'THRU', '10', 'BY', 2])
        values2 = expand_thru_case_control(['1', 'THRU', '10', 'BY', 2])
        values3 = expand_thru_case_control(['1 THRU 10 BY 2'])
        values4 = expand_thru_case_control(['1 THRU 10 BY 2 '])
        assert values1 == [1, 3, 5, 7, 9, 10], values1
        assert values2 == [1, 3, 5, 7, 9, 10], values2
        assert values3 == [1, 3, 5, 7, 9, 10], values3
        assert values4 == [1, 3, 5, 7, 9, 10], values4

        values1 = expand_thru_by(['1', 'thru', '10', 'by', 2])
        values2 = expand_thru_case_control(['1', 'thru', '10', 'by', 2])
        values3 = expand_thru_case_control(['1 thru 10 by 2'])
        values4 = expand_thru_case_control(['1 thru 10, by, 2,'])
        assert values1 == [1, 3, 5, 7, 9, 10], values1
        assert values2 == [1, 3, 5, 7, 9, 10], values2
        assert values3 == [1, 3, 5, 7, 9, 10], values3
        assert values4 == [1, 3, 5, 7, 9, 10], values4

        values1 = expand_thru_by([1, 2, 3, 4, 5])
        values2 = expand_thru_case_control([1, 2, 3, 4, 5])
        assert values1 == [1, 2, 3, 4, 5], values1
        assert values2 == [1, 2, 3, 4, 5], values2

        values1 = expand_thru_case_control(['1,5,THRU,11,EXCEPT,7,8,13'])
        values2 = expand_thru_case_control(
            [1, 5, 'THRU', 11, 'EXCEPT', 7, 8, 13])
        assert values1 == [1, 5, 6, 9, 10, 11, 13], values1
        assert values2 == [1, 5, 6, 9, 10, 11, 13], values2