def test_add_summary_merge_with_existing(self): with ioutil.TempDir() as td: sb = sandbox.Sandbox(os.path.join(td.path, 'buildscripts.trunk.dev')) sb.layout() es = get_sample_eval_summary() db = Dashboard(sb.get_report_root()) start_time = es.get_start_time() start_text = str(es) fldr = os.path.join(sb.get_report_root(), 'zufa') os.makedirs(fldr) fname = os.path.join(fldr, 'results.txt') with open(fname, 'w') as f: for i in range(100): # Make it look like the results file has 100 entries, spaced 4 # hrs apart, stretching back 400 hrs. At 168 hrs per week, this # should look like about 2.5 weeks of history. es.start_time -= (4 * 3600) f.write(str(es) + '\n') es.start_time = start_time db.add_summary(es) with open(fname, 'r') as f: lines = [l.strip() for l in f.readlines()] self.assertEqual(start_text, lines[0]) self.assertEqual(85, len(lines)) ld = dateutils.format_standard_date_with_tz_offset(dateutils.parse_standard_date_with_tz_offset('2011-08-27 14:51:40.490000-0600')) self.assertEqual('sadm.trunk.136.20,OFFICIAL,zufa,TEST,,' + ld + ',11.08 0.44 9.18,linux_x86-64,Linux,64,2.6.35.13-92.fc14', lines[1]) ld = dateutils.format_standard_date_with_tz_offset(dateutils.parse_standard_date_with_tz_offset('2011-08-13 18:51:40.490000-0600')) self.assertEqual('sadm.trunk.136.20,OFFICIAL,zufa,TEST,,' + ld + ',11.08 0.44 9.18,linux_x86-64,Linux,64,2.6.35.13-92.fc14', lines[84])
def test_format_and_parse_tandard_date_with_tz_offset(self): when = round(time.time(), 3) x = dateutils.format_standard_date_with_tz_offset(when) if not re.match(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d+)?\s*[-+]\d\d:?\d\d', x): self.fail('Expected standard format; got "%s" instead.' % x) when2 = round(dateutils.parse_standard_date_with_tz_offset(x), 3) if when != when2: self.fail('Expected round trip to be lossless. Instead, started with %d and ended with %d (diff = %d)' % (int(when), when2, when2-int(when)))
def parse_eval_summary_line(line): ''' Convert a line of text into an EvalResult. Raise exception on bad format. ''' fields = [x.strip() for x in line.split(',')] fields[-6] = dateutils.parse_standard_date_with_tz_offset(fields[-6]) fields[-5] = [float(val) for val in fields[-5].split(' ')] try: return EvalSummary(*fields) except: import traceback traceback.print_exc()
def test_format_and_parse_tandard_date_with_tz_offset(self): when = round(time.time(), 3) x = dateutils.format_standard_date_with_tz_offset(when) if not re.match( r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d+)?\s*[-+]\d\d:?\d\d', x): self.fail('Expected standard format; got "%s" instead.' % x) when2 = round(dateutils.parse_standard_date_with_tz_offset(x), 3) if when != when2: self.fail( 'Expected round trip to be lossless. Instead, started with %d and ended with %d (diff = %d)' % (int(when), when2, when2 - int(when)))
def inherit(path, update_msg=None): # print('inheriting %s' % path) if Lock._lock_exists(path): lk = Lock() f = open(path, "r") rows = [row.strip().split("=") for row in f.readlines() if row and row.find("=") > -1] for row in rows: attr = row[0].strip().replace(" ", "_") val = row[1].strip() if attr.endswith("date"): val = dateutils.parse_standard_date_with_tz_offset(val) lk.__dict__[attr] = val lk.inherited = True lk.path = path if update_msg: lk.update(update_msg) return lk
def inherit(path, update_msg=None): #print('inheriting %s' % path) if Lock._lock_exists(path): lk = Lock() f = open(path, 'r') rows = [ row.strip().split('=') for row in f.readlines() if row and row.find('=') > -1 ] for row in rows: attr = row[0].strip().replace(' ', '_') val = row[1].strip() if attr.endswith('date'): val = dateutils.parse_standard_date_with_tz_offset(val) lk.__dict__[attr] = val lk.inherited = True lk.path = path if update_msg: lk.update(update_msg) return lk
def _get_date_conf(self, section, key, default=None): value = self._get_conf(section, key, default) if value: value = dateutils.parse_standard_date_with_tz_offset(value) return value