Code Duplication    Length = 6-8 lines in 7 locations

tests/tests_history.py 7 locations

@@ 138-145 (lines=8) @@
135
        self.assertEqual(res[0].Value.Value, self.values[0])
136
137
    # start time greater than end time, should return reverse order
138
    def test_history_var_read_5_in_timeframe_start_greater_than_end(self):
139
        now = datetime.utcnow()
140
        old = now - timedelta(days=6)
141
142
        res = self.var.read_raw_history(now, old, 5)
143
        self.assertEqual(len(res), 5)
144
        self.assertEqual(res[-1].Value.Value, self.values[-5])
145
        self.assertEqual(res[0].Value.Value, self.values[-1])
146
    
147
    # only start return original order
148
    def test_history_var_read_6_with_start(self):
@@ 128-135 (lines=8) @@
125
        self.assertEqual(res[-1].Value.Value, self.values[-1])
126
        self.assertEqual(res[0].Value.Value, self.values[0])
127
128
    def test_history_var_read_5_in_timeframe(self):
129
        now = datetime.utcnow()
130
        old = now - timedelta(days=6)
131
132
        res = self.var.read_raw_history(old, now, 5)
133
        self.assertEqual(len(res), 5)
134
        self.assertEqual(res[-1].Value.Value, self.values[4])
135
        self.assertEqual(res[0].Value.Value, self.values[0])
136
137
    # start time greater than end time, should return reverse order
138
    def test_history_var_read_5_in_timeframe_start_greater_than_end(self):
@@ 119-126 (lines=8) @@
116
        self.assertEqual(res[-1].Value.Value, self.values[-2])
117
    
118
    # both start and endtime, return from start to end
119
    def test_history_var_read_all(self):
120
        now = datetime.utcnow()
121
        old = now - timedelta(days=6)
122
123
        res = self.var.read_raw_history(old, now, 0)
124
        self.assertEqual(len(res), 20)
125
        self.assertEqual(res[-1].Value.Value, self.values[-1])
126
        self.assertEqual(res[0].Value.Value, self.values[0])
127
128
    def test_history_var_read_5_in_timeframe(self):
129
        now = datetime.utcnow()
@@ 157-163 (lines=7) @@
154
        self.assertEqual(res[0].Value.Value, self.values[0])
155
156
    # only start return original order
157
    def test_history_var_read_all_with_start(self):
158
        now = datetime.utcnow()
159
        old = now - timedelta(days=6)
160
        res = self.var.read_raw_history(old, None, 0)
161
        self.assertEqual(len(res), 20)
162
        self.assertEqual(res[-1].Value.Value, self.values[-1])
163
        self.assertEqual(res[0].Value.Value, self.values[0])
164
165
    # only end return reversed order
166
    def test_history_var_read_all_with_end(self):
@@ 148-154 (lines=7) @@
145
        self.assertEqual(res[0].Value.Value, self.values[-1])
146
    
147
    # only start return original order
148
    def test_history_var_read_6_with_start(self):
149
        now = datetime.utcnow()
150
        old = now - timedelta(days=6)
151
        res = self.var.read_raw_history(old, None, 6)
152
        self.assertEqual(len(res), 6)
153
        self.assertEqual(res[-1].Value.Value, self.values[5])
154
        self.assertEqual(res[0].Value.Value, self.values[0])
155
156
    # only start return original order
157
    def test_history_var_read_all_with_start(self):
@@ 174-179 (lines=6) @@
171
        self.assertEqual(res[0].Value.Value, self.values[-1])
172
173
    # only end return reversed order
174
    def test_history_var_read_3_with_end(self):
175
        end = datetime.utcnow() + timedelta(days=6)
176
        res = self.var.read_raw_history(None, end, 3)
177
        self.assertEqual(len(res), 3)
178
        self.assertEqual(res[2].Value.Value, self.values[-3])
179
        self.assertEqual(res[0].Value.Value, self.values[-1])
180
181
    # ~~~~~~~~~~~~~~~~~~~~~~~ events ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182
@@ 166-171 (lines=6) @@
163
        self.assertEqual(res[0].Value.Value, self.values[0])
164
165
    # only end return reversed order
166
    def test_history_var_read_all_with_end(self):
167
        end = datetime.utcnow() + timedelta(days=6)
168
        res = self.var.read_raw_history(None, end, 0)
169
        self.assertEqual(len(res), 20)
170
        self.assertEqual(res[-1].Value.Value, self.values[0])
171
        self.assertEqual(res[0].Value.Value, self.values[-1])
172
173
    # only end return reversed order
174
    def test_history_var_read_3_with_end(self):