Skip to content

Commit 4e854a5

Browse files
author
Konstantinacc
committed
Changed resume_log and create_log order inside utils.py.
1 parent e513b9f commit 4e854a5

File tree

1 file changed

+96
-97
lines changed

1 file changed

+96
-97
lines changed

codebender_testing/utils.py

Lines changed: 96 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,102 @@ def delete_project(self, project_name):
400400
except:
401401
pass
402402

403+
def resume_log (self, logfile, compile_type, sketches):
404+
"""Resume previous log, if any. Coves 3 cases:
405+
Case 1: Test runs for 1st time and there is no previous log file.
406+
Case 2: Test runs for 2nd time and there is a previous log file which contains
407+
some of the urls that should be compiled and log file should be completed with
408+
the rest.
409+
Case 3: Test runs for 2nd time and there is a previous log file which contains
410+
all the urls that should be compiled and test should be run again for all urls.
411+
"""
412+
"""Creates a variable in which current date and time are stored."""
413+
log_time = gmtime()
414+
415+
"""Creates an empty dictionary each time that a test runs."""
416+
log_entry = {}
417+
418+
"""Creates an empty dictionary each time that a test runs."""
419+
urls_visited = {}
420+
421+
"""Calls `read_last_log` function and checks if there is a previous log file
422+
of the same compile_type (e.g. sketch). If there is, a dictionary containing
423+
`timestamp` and `log` keys with their corresponding values is returned.
424+
Otherwise, a dictionary where `timestamp` and `log` values are `None` is returned.
425+
No previous log:
426+
{'timestamp': None, 'log': None}
427+
Previous log exists:
428+
{'timestamp': '2016-02-14_10-42-17',
429+
'log': {
430+
'https://staging.codebender.cc/sketch:30360': {'success': ['Arduino Uno']},
431+
'https://staging.codebender.cc/sketch:30352': {'success': ['Arduino Uno']}
432+
}
433+
}
434+
"""
435+
last_log = read_last_log(compile_type)
436+
437+
if compile_type != 'target_library' and last_log['log']:
438+
"""Checks if `last_log[log]` has a value (is not `None`).
439+
If it has, this means that there is a log file created previously and dictionaries
440+
`log_entry` and `urls_visited` should be updated.
441+
{'timestamp': '2016-02-14_12-44-16',
442+
'log': {
443+
'https://staging.codebender.cc/sketch:30360': {'success': ['Arduino Uno']},
444+
'https://staging.codebender.cc/sketch:30352': {'success': ['Arduino Uno']}
445+
}
446+
}
447+
"""
448+
if last_log['log']:
449+
log_time = strptime(last_log['timestamp'], '%Y-%m-%d_%H-%M-%S')
450+
451+
""" Test has stopped its execution for some reason, (e.g.to avoid saucelabs timeout)
452+
and `log_entry` dictionary will be filled with the entries of `last_log[log]` values.
453+
log_entry = {'https://staging.codebender.cc/sketch:30360': {'success': ['Arduino Uno']},
454+
'https://staging.codebender.cc/sketch:30352': {'success': ['Arduino Uno']}}
455+
"""
456+
log_entry = last_log['log']
457+
458+
""" Test has stopped its execution for some reason,(e.g.to avoid saucelabs timeout)
459+
and `urls_visited` dictionary will be filled with the urls already visited when the test stopped.
460+
urls_visited = {'https://staging.codebender.cc/sketch:30360': True,
461+
'https://staging.codebender.cc/sketch:30352': True}
462+
"""
463+
for url in last_log['log']:
464+
urls_visited[url] = True
465+
466+
"""Creates an empty dictionary each time that a test runs."""
467+
urls_to_visit = []
468+
469+
"""If a test has stopped its execution for some reason,
470+
(e.g.to avoid saucelabs timeout) `urls_to_visit` dictionary will
471+
be filled with the urls that remain to be visited.
472+
urls_to_visit = {'https://staging.codebender.cc/sketch:30358',
473+
'https://staging.codebender.cc/sketch:30355'}
474+
"""
475+
for url in sketches:
476+
if url not in urls_visited:
477+
urls_to_visit.append(url)
478+
479+
"""If the urls_to_visit is empty, this means that the test was completed
480+
and should start again. `urls_to_visit` equals to all `sketches` and `log_entry`
481+
is an empty dictionary.
482+
"""
483+
if len(urls_to_visit) == 0:
484+
urls_to_visit = sketches
485+
log_entry = {}
486+
log_time = gmtime()
487+
488+
""" If `logfile` has a value and is not `None` we create `log_file`."""
489+
if logfile:
490+
log_file = strftime(logfile, log_time)
491+
492+
return (urls_to_visit, log_entry, log_file, log_time)
493+
494+
def create_log (self, log_file, log_entry,compile_type):
495+
# Dump the test results to `log_file`.
496+
with open(log_file, 'w') as f:
497+
f.write(jsondump(log_entry))
498+
403499
def open_all_libraries_and_examples(self, url, logfile):
404500
self.open(url)
405501
examples = self.execute_script(_GET_SKETCHES_SCRIPT.format(selector='.accordion li a'), '$')
@@ -505,103 +601,6 @@ def compile_all_sketches(self, url, selector, **kwargs):
505601
assert len(sketches) > 0
506602
self.compile_sketches(sketches, **kwargs)
507603

508-
def resume_log (self, logfile, compile_type, sketches):
509-
"""Resume previous log, if any. Coves 3 cases:
510-
Case 1: Test runs for 1st time and there is no previous log file.
511-
Case 2: Test runs for 2nd time and there is a previous log file which contains
512-
some of the urls that should be compiled and log file should be completed with
513-
the rest.
514-
Case 3: Test runs for 2nd time and there is a previous log file which contains
515-
all the urls that should be compiled and test should be run again for all urls.
516-
"""
517-
"""Creates a variable in which current date and time are stored."""
518-
log_time = gmtime()
519-
520-
"""Creates an empty dictionary each time that a test runs."""
521-
log_entry = {}
522-
523-
"""Creates an empty dictionary each time that a test runs."""
524-
urls_visited = {}
525-
526-
"""Calls `read_last_log` function and checks if there is a previous log file
527-
of the same compile_type (e.g. sketch). If there is, a dictionary containing
528-
`timestamp` and `log` keys with their corresponding values is returned.
529-
Otherwise, a dictionary where `timestamp` and `log` values are `None` is returned.
530-
No previous log:
531-
{'timestamp': None, 'log': None}
532-
Previous log exists:
533-
{'timestamp': '2016-02-14_10-42-17',
534-
'log': {
535-
'https://staging.codebender.cc/sketch:30360': {'success': ['Arduino Uno']},
536-
'https://staging.codebender.cc/sketch:30352': {'success': ['Arduino Uno']}
537-
}
538-
}
539-
"""
540-
last_log = read_last_log(compile_type)
541-
542-
if compile_type != 'target_library' and last_log['log']:
543-
"""Checks if `last_log[log]` has a value (is not `None`).
544-
If it has, this means that there is a log file created previously and dictionaries
545-
`log_entry` and `urls_visited` should be updated.
546-
{'timestamp': '2016-02-14_12-44-16',
547-
'log': {
548-
'https://staging.codebender.cc/sketch:30360': {'success': ['Arduino Uno']},
549-
'https://staging.codebender.cc/sketch:30352': {'success': ['Arduino Uno']}
550-
}
551-
}
552-
"""
553-
if last_log['log']:
554-
log_time = strptime(last_log['timestamp'], '%Y-%m-%d_%H-%M-%S')
555-
556-
""" Test has stopped its execution for some reason, (e.g.to avoid saucelabs timeout)
557-
and `log_entry` dictionary will be filled with the entries of `last_log[log]` values.
558-
log_entry = {'https://staging.codebender.cc/sketch:30360': {'success': ['Arduino Uno']},
559-
'https://staging.codebender.cc/sketch:30352': {'success': ['Arduino Uno']}}
560-
"""
561-
log_entry = last_log['log']
562-
563-
""" Test has stopped its execution for some reason,(e.g.to avoid saucelabs timeout)
564-
and `urls_visited` dictionary will be filled with the urls already visited when the test stopped.
565-
urls_visited = {'https://staging.codebender.cc/sketch:30360': True,
566-
'https://staging.codebender.cc/sketch:30352': True}
567-
"""
568-
for url in last_log['log']:
569-
urls_visited[url] = True
570-
571-
"""Creates an empty dictionary each time that a test runs."""
572-
urls_to_visit = []
573-
574-
"""If a test has stopped its execution for some reason,
575-
(e.g.to avoid saucelabs timeout) `urls_to_visit` dictionary will
576-
be filled with the urls that remain to be visited.
577-
urls_to_visit = {'https://staging.codebender.cc/sketch:30358',
578-
'https://staging.codebender.cc/sketch:30355'}
579-
"""
580-
for url in sketches:
581-
if url not in urls_visited:
582-
urls_to_visit.append(url)
583-
584-
"""If the urls_to_visit is empty, this means that the test was completed
585-
and should start again. `urls_to_visit` equals to all `sketches` and `log_entry`
586-
is an empty dictionary.
587-
"""
588-
if len(urls_to_visit) == 0:
589-
urls_to_visit = sketches
590-
log_entry = {}
591-
log_time = gmtime()
592-
593-
""" If `logfile` has a value and is not `None` we create `log_file`."""
594-
if logfile:
595-
log_file = strftime(logfile, log_time)
596-
597-
return (urls_to_visit, log_entry, log_file, log_time)
598-
599-
def create_log (self, log_file, log_entry,compile_type):
600-
# Dump the test results to `log_file`.
601-
with open(log_file, 'w') as f:
602-
f.write(jsondump(log_entry))
603-
604-
605604
def compile_sketches(self, sketches, iframe=False, project_view=False, logfile=None, compile_type='sketch', create_report=False, comment=False):
606605
"""Compiles the sketches with URLs given by the `sketches` list.
607606
`logfile` specifies a path to a file to which test results will be

0 commit comments

Comments
 (0)