• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

timcera / pyslice / 12340932278

15 Dec 2024 05:42PM CUT coverage: 45.447%. Remained the same
12340932278

Pull #4

github

web-flow
Merge d90cfa984 into 2ffee6f33
Pull Request #4: build(deps): bump actions/setup-python from 4 to 5

529 of 1164 relevant lines covered (45.45%)

2.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.27
/src/pyslice/pyslice_lib/PySPG/ParamIterators.py
1
"""
2
:::~ Copyright (C) 2005 by Claudio J. Tessone <tessonec@imedea.uib.es>
3

4
Created on: 09 Jan 2005
5

6
Copyright: Distributed according to GNU/GPL Version 2
7
           (see http://www.gnu.org)
8
"""
9

10

11
class SPGIterator:
5✔
12
    """This is a subsidiary abstract class for the ParamParser one.  It defines
13
    the iteration type in the constructor. Must be subclassed (it's abstract)
14
    In principle there is no need to touch anything here (well, you can always
15
    improve the code) only you must subclass this object if you wish to add
16
    other iterator types.
17
    """
18

19
    def __init__(self):
5✔
20
        self.index = 0
5✔
21
        self.varname = False
5✔
22
        self.data = []
5✔
23

24
    def __iter__(self):
5✔
25
        return self.data.__iter__()
×
26

27
    def is_variable(self):
5✔
28
        return True
5✔
29

30
    def set_command(self):
5✔
31
        """This is the function called to generate all the possible values of
32
        the iterator it returns the variable name and all the possible values
33
        it can take command holds the input line in the parameters file,
34
        separator is the character delimiting fields (if separator = None, any
35
        space is considered a separator)
36
        """
37

38
    def __next__(self):
5✔
39
        self.index += 1
5✔
40
        if self.index == len(self.data):
5✔
41
            raise StopIteration
5✔
42

43
        return self.data[self.index]
5✔
44

45
    def reset(self):
5✔
46
        self.index = 0
5✔
47
        return self.data[0]
5✔
48

49
    def get_varname(self):
5✔
50
        return self.varname
5✔
51

52
    def get_value(self):
5✔
53
        return self.data[self.index]
5✔
54

55

56
class ItOperator(SPGIterator):
5✔
57
    """This subclass generates the values for classes defined according to the
58
    rule @var_name val_min val_max step where @ is the operation defined for
59
    the data type.  var_name is the variable name val_min, val_max the bounds
60
    step  the step the actualization process runs according to actual_value
61
    = actual_value @ step
62
    """
63

64
    def __init__(self, it_type):
5✔
65
        SPGIterator.__init__(self)
5✔
66
        self.it_type = it_type
5✔
67

68
    def set_command(self, command, separator=" "):
5✔
69
        str_rest = command.split(separator)
5✔
70
        self.varname = str_rest[0].strip()
5✔
71
        # try:
72
        [xmin, xmax, xstep] = list(map(eval, str_rest[1:]))
5✔
73
        # except ValueError:
74
        #    raise ValueError(
75
        #        f"Line: '{command}' incorrect number of parameters (found {len(str_rest) - 1}) for iterator       '{self.it_type}' over '{self.varname}'"
76
        #    )
77
        #    #
78
        #    #   Block that raises exception in the case that iteration
79
        #    #   requested do not reaches xmax
80

81
        try:
5✔
82
            if (xmin < xmax) and (xmin >= eval(f"{xmin} {self.it_type} {xstep}")):
5✔
83
                raise AssertionError("")
×
84

85
            if (xmin > xmax) and (xmin <= eval(f"{xmin} {self.it_type} {xstep}")):
5✔
86
                raise AssertionError("")
×
87
        except AssertionError:
×
88
            raise ValueError(
×
89
                f"Line: '{command}' Variable '{self.varname}': Error! {xmin}{self.it_type}{xstep} do not seem to tend to {xmax}"
90
            )
91

92
        lsTmp = []
5✔
93
        xact = xmin
5✔
94

95
        while (xmin > xmax) ^ (xact <= xmax):  # ^ is xor in python !
5✔
96
            lsTmp.append(xact)
5✔
97
            xact = eval(f"{xact}{self.it_type}{xstep}")
5✔
98

99
        self.data = lsTmp
5✔
100

101

102
class ItOperatorPlus(ItOperator):
5✔
103
    def __init__(self):
5✔
104
        ItOperator.__init__(self, "+")
5✔
105

106

107
class ItOperatorMinus(ItOperator):
5✔
108
    def __init__(self):
5✔
109
        ItOperator.__init__(self, "-")
×
110

111

112
class ItOperatorProduct(ItOperator):
5✔
113
    def __init__(self):
5✔
114
        ItOperator.__init__(self, "*")
5✔
115

116

117
class ItOperatorDivision(ItOperator):
5✔
118
    def __init__(self):
5✔
119
        ItOperator.__init__(self, "/")
×
120

121

122
class ItOperatorPower(ItOperator):
5✔
123
    def __init__(self):
5✔
124
        ItOperator.__init__(self, "**")
×
125

126

127
class ItConstant(SPGIterator):
5✔
128
    """This subclass generates a constant "iteration" type."""
129

130
    def __init__(self):
5✔
131
        SPGIterator.__init__(self)
×
132

133
    def is_variable(self):
5✔
134
        return False
×
135

136
    def set_command(self, command, separator=" "):
5✔
137
        self.varname = command.strip().split(separator)[0]
×
138
        self.data = [separator.join(command.strip().split(separator)[1:])]
×
139
        self.index = 0
×
140

141

142
class ItPunctual(SPGIterator):
5✔
143
    """This subclass generates a list of defined values in command command
144
    should be .var_name value1 value2 value3 ... and so on
145
    """
146

147
    def __init__(self):
5✔
148
        SPGIterator.__init__(self)
5✔
149

150
    def set_command(self, command, separator=" "):
5✔
151
        str_rest = command.split(separator)
5✔
152
        self.varname = str_rest[0].strip()
5✔
153
        self.data = [i.strip() for i in str_rest[1:]]
5✔
154

155

156
class ItRepetition(SPGIterator):
5✔
157
    """This subclass generates a list of null with length defined useful when
158
    trying to repit the run of the program with the same parameters.
159
    """
160

161
    def __init__(self):
5✔
162
        SPGIterator.__init__(self)
×
163

164
    def set_command(self, command, separator=" "):
5✔
165
        self.varname = False
×
166
        self.data = list(range(eval(command)))
×
167

168
    def is_variable(self):
5✔
169
        return False
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc