Skip to content

Commit 9552276

Browse files
committed
Merge pull request #30 from codebendercc/fixed-comments-in-libraries-without-examples
Fixed comments in libraries without examples
2 parents 6aef03a + 7423dd7 commit 9552276

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

codebender_testing/disqus.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ def update_comment(self, sketch, results, current_date, log_entry, openFailFlag,
7171
if library_match:
7272
library = library_match.group(1)
7373

74-
#Check if the currently compiled example belongs to the same library as the previous one.
74+
# Check if the currently compiled example belongs to the same library as the previous one.
7575
# To do so we check if value of library is the same with self.last library value which is updated
7676
# every time that we log the results of a compiled example.
7777
if library != self.last_library:
7878
library_to_comment = library
7979

80-
#Check if we should add a comment to the library.
80+
# Check if we should add a comment to the library.
8181
if library_to_comment and library not in self.examples_without_library:
8282
log_entry = self.handle_library_comment(library_to_comment, current_date, log_entry)
8383

8484
self.last_library = library
85-
#Add a comment to the currently compiled library example.
85+
# Add a comment to the currently compiled library example.
8686
if not openFailFlag:
8787
log_entry = self.handle_example_comment(sketch, results, current_date, log_entry)
8888

@@ -112,21 +112,21 @@ def handle_library_comment(self, library, current_date, log, examples=True):
112112
comment_updated = False
113113

114114
new_message = self.messages['library'].replace('TEST_DATE', current_date)
115-
if examples==False:
115+
if examples == False:
116116
new_message = self.messages['library_no_examples'].replace('TEST_DATE', current_date)
117117

118118
for thread in paginator:
119119

120120
# Check if library has already a comment.
121121
post_id, existing_message = self.get_posts(thread['id'])
122122

123-
#If library already has a comment, update it.
123+
# If library already has a comment, update it.
124124
if post_id and existing_message:
125125
log[url]['comment'] = self.update_post(post_id, new_message)
126126
comment_updated = True
127127
break
128128

129-
#If library doesn't have a comment, create it.
129+
# If library doesn't have a comment, create it.
130130
if not comment_updated:
131131
log[url]['comment'] = self.create_post(identifier, new_message)
132132

codebender_testing/utils.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ def throttle_compile():
9393
with open(BOARDS_PATH) as f:
9494
BOARDS_DB = simplejson.loads(f.read())
9595

96+
# Display progress
97+
def display_progress(status):
98+
sys.stdout.write(status)
99+
sys.stdout.flush()
100+
96101
def read_last_log(compile_type):
97102
logs = os.listdir(get_path('logs'))
98103
logs_re = re.compile(r'.+cb_compile_tester.+')
@@ -545,7 +550,7 @@ def open_all_libraries_and_examples(self, url, logfile):
545550
url_name = url.split('/')[-1]
546551
name = self.get_element(By.CSS_SELECTOR, '#mycontainer h1 small').text
547552
name = re.sub('[()]', '', name).split('.')[0]
548-
if (name != url_name):
553+
if name != url_name:
549554
print "Didn't open url: ", url
550555

551556
test_status = True
@@ -641,27 +646,36 @@ def comment_compile_libraries_examples(self, sketches, library_examples_dic={},
641646
library_re = re.compile(r'^.+/library/.+$')
642647

643648
for url in urls_to_visit:
644-
645649
if library_re.match(url):
646650
library = url.split('/')[-1]
647-
for key, value in library_examples_dic.iteritems():
648-
if(key == library and len(value) == 0):
651+
try:
652+
# Comment libraries without examples
653+
if len(library_examples_dic[library]) == 0:
649654
if logfile is None or not self.run_full_compile_tests:
650655
toc = time.time()
651656
continue
652657

653658
# Update Disqus comments.
654659
current_date = strftime('%Y-%m-%d', log_time)
655660
if comment and compile_type in ['library', 'target_library']:
656-
library=key
657-
examples=False
661+
self.open(url)
662+
self.get_element(By.CSS_SELECTOR, '#mycontainer h1')
663+
examples = False
658664
log_entry = disqus_wrapper.handle_library_comment(library, current_date, log_entry, examples)
659665
self.create_log(log_file, log_entry, compile_type)
660-
toc = time.time()
661-
if (toc - tic) >= SAUCELABS_TIMEOUT_SECONDS:
662-
print '\nStopping tests to avoid saucelabs timeout'
663-
print 'Test duration:', int(toc - tic), 'sec'
664-
return
666+
667+
test_status = '.'
668+
if not log_entry[url]['comment']:
669+
test_status = 'F'
670+
display_progress(test_status)
671+
except Exception as error:
672+
print error
673+
674+
toc = time.time()
675+
if (toc - tic) >= SAUCELABS_TIMEOUT_SECONDS:
676+
print '\nStopping tests to avoid saucelabs timeout'
677+
print 'Test duration:', int(toc - tic), 'sec'
678+
return
665679
else:
666680
sketch = url
667681
# Read the boards map in case current sketch/example requires a special board configuration.
@@ -726,9 +740,7 @@ def comment_compile_libraries_examples(self, sketches, library_examples_dic={},
726740

727741
self.create_log(log_file, log_entry, compile_type)
728742

729-
# Display progress
730-
sys.stdout.write(test_status)
731-
sys.stdout.flush()
743+
display_progress(test_status)
732744

733745
toc = time.time()
734746
if (toc - tic) >= SAUCELABS_TIMEOUT_SECONDS:
@@ -835,9 +847,7 @@ def compile_sketches(self, sketches, iframe=False, project_view=False, logfile=N
835847

836848
self.create_log(log_file, log_entry, compile_type)
837849

838-
# Display progress
839-
sys.stdout.write(test_status)
840-
sys.stdout.flush()
850+
display_progress(test_status)
841851

842852
toc = time.time()
843853
if toc - tic >= SAUCELABS_TIMEOUT_SECONDS:

0 commit comments

Comments
 (0)