# -*- coding: utf-8 -*- """Reports that fold: what opens, what stays shut, and what is never lost. The rule under test is the owner's, 2026-08-30: everything below the answer starts folded, and a section opens itself only when it has a problem in it. The value of that is a contract -- "if nothing below the headline is open, nothing needs me" -- and the contract is worth more than any single section being visible. So the tests are mostly about the two ways it could be broken: a section that has a problem and does not open, and a section that folds a sentence out of existence rather than folding it away. The HTML half is written for pyRevit's output panel, which is an IE-engine `System.Windows.Forms.WebBrowser`. `
` does not exist there and fails SILENTLY -- the "collapsed" content simply renders. That is the trap this module exists to avoid, so it is asserted directly. """ # pylint: disable=import-error,invalid-name import re from vibe import foldreport as fold def _section(**kw): kw.setdefault('key', 's1') kw.setdefault('title', 'Some detail') return fold.Section(**kw) # --------------------------------------------------------- what opens itself def test_a_routine_section_is_folded(): assert _section(summary='3 things').is_open is False def test_a_section_with_a_problem_opens_itself(): assert _section(problem='2 checks did not run').is_open is True def test_the_answer_is_never_folded(): assert _section(headline=True).is_open is True def test_a_problem_is_a_sentence_not_a_flag(): """A section that opens has to say why it opened, or the reader has to read the whole of it to find out.""" section = _section(problem='the index is 4 day(s) old') assert 'day(s) old' in fold.blocks([section])[0][1] def test_the_contract_is_readable_off_the_section_list(): sections = [_section(key='a'), _section(key='b', problem='something')] assert [s.key for s in fold.sections_with_problems(sections)] == ['b'] assert fold.problem_count(sections) == 1 # ------------------------------------------------------- folded is not gone def test_a_folded_section_still_names_itself_and_what_it_holds(): section = _section(title='The donor pool', summary='690 looked at, 204 kept', blocks=[('md', 'a long table nobody reads')]) line = fold.blocks([section])[0][1] assert 'The donor pool' in line assert '690 looked at, 204 kept' in line assert 'folded' in line assert 'nobody reads' not in line # folded away, not printed def test_show_all_prints_every_section_in_full(): section = _section(blocks=[('md', 'the detail')]) text = fold.text([section], show_all=True) assert 'the detail' in text def test_the_headline_is_printed_without_a_fold_header(): head = _section(key='headline', title='Answer', headline=True, blocks=[('md', '# The answer')]) got = fold.blocks([head]) assert got == [('md', '# The answer')] # ------------------------------------------------------------- as plain text def test_entities_become_ascii_and_the_words_are_left_alone(): got = fold.md_text('This is **bold** — and `code`.') assert 'This is bold -- and code.' in got assert '—' not in got def test_a_quote_block_is_marked_so_a_caveat_cannot_look_like_prose(): assert fold.md_text('> a warning').lstrip().startswith('!') def test_a_path_is_never_broken_across_two_lines(): """A wrapped path is not a wrapped sentence, it is an unusable value -- the reader copies these into a shell or into Select by ID.""" path = 'C:\\a\\very\\long\\folder\\name\\that\\exceeds\\the\\margin\\x.txt' got = fold.md_text('written to `' + path + '`') assert path in got def test_a_table_never_truncates_a_mark_however_wide_the_row_gets(): """A silently cut mark is a wrong answer that looks like a right one.""" got = fold.table_text(['donor', 'what'], [['PNL803', 'x' * 120], ['PNL804', 'y']]) assert 'PNL803' in got and 'PNL804' in got assert 'x' * 120 in got def test_an_empty_table_says_nothing_rather_than_printing_a_header(): assert 'nothing' in fold.table_text(['a'], []) # -------------------------------------------------------------------- as HTML def test_the_html_never_uses_details_which_this_panel_cannot_render(): """pyRevit's output is an IE-engine WebBrowser. `
` renders as an inline span there, so a 'collapsed' section would simply be visible -- the failure is silent, which is why it is asserted rather than trusted.""" got = fold.html([_section(blocks=[('md', 'x')])]) assert 'bad()']]) assert '