def test_sorting(tmp_path): """Test that automated ordering based on tags works.""" r = Report() r.add_code(code='E = m * c**2', title='intelligence >9000', tags=('bem', )) r.add_code(code='a**2 + b**2 = c**2', title='Pythagoras', tags=('evoked', )) r.add_code(code='🧠', title='source of truth', tags=('source-estimate', )) r.add_code(code='🥦', title='veggies', tags=('raw', )) # Check that repeated calls of add_* actually continuously appended to # the report orig_order = ['bem', 'evoked', 'source-estimate', 'raw'] assert [c.tags[0] for c in r._content] == orig_order # Now check the actual sorting content_sorted = r._sort(content=r._content, order=CONTENT_ORDER) expected_order = ['raw', 'evoked', 'bem', 'source-estimate'] assert content_sorted != r._content assert [c.tags[0] for c in content_sorted] == expected_order r.save(fname=op.join(tmp_path, 'report.html'), sort_content=True, open_browser=False)