def _align_block(block, s=1, p=1, c=2, m=1): # Split score block into individual events event_list = block.splitlines() # Get the number of columns in block n_columns = max(event.number_of_pfields(e) for e in event_list) # Initialize pfield lengths with zeros pf_lengths = [0] * n_columns # Get the longest pfield lengths for each column for row in event_list: for i, col in enumerate(event.get_pfield_list(row)): pf_lengths[i] = max(len(col), pf_lengths[i]) # Align pfields, without trailing comments align_pfields = [] for e in event_list: line = [] # Append score statement with whitespace determined by s line.append(event.get(e, 0).ljust(s + 1)) # Appened each pfield with whitespace determined by p and m for i, L in enumerate(pf_lengths[1:event.number_of_pfields(e)]): line.append(event.get(e, i + 1).ljust(max(L, m))) line.append(''.ljust(p)) # Strip end of any potential whitespace align_pfields.append(''.join(line).rstrip(' ')) # Add trailing comments align_comments = [] longest_event = max(len(e) for e in align_pfields) for i, e in enumerate(event_list): line = [] line.append(''.join(align_pfields[i])) # Add whitespace and comment if comment exists if event.get_trailing_comment(e): line.append(''.ljust(longest_event - len(align_pfields[i]))) line.append(''.ljust(c)) line.append(event.get_trailing_comment(e)) align_comments.append(''.join(line)) return '\n'.join(align_comments) + '\n'
def test(n, e, expect): result = s.get_trailing_comment(e) did_pass = result == expect return did_pass, n, 'get_trailing_comment', str(expect), str(result)