def test_dedent_all__with_params(): dedented_joined_text = snick.dedent_all( """ Here is the first blob with 8 spaces of indentation that should be dedented first. """, " Here is another single line with 2 spaces of indent.", "This line has no indentation.\n", should_strip=False, join_str="\n\n", ) assert dedented_joined_text == snick.dedent( """ Here is the first blob with 8 spaces of indentation that should be dedented first. Here is another single line with 2 spaces of indent. This line has no indentation. """, should_strip=False, )
def test_conjoin__default(): joined_text = snick.conjoin( "Here are some lines", "that should be joined", "into a single multi-line string", ) assert joined_text == snick.dedent(""" Here are some lines that should be joined into a single multi-line string """)
def test_stencil__handles_filter_block_correctly(self): template = self.jinja_env.from_string( snick.dedent( """ Some Text that should always be included {%- filter stencil('foo') %} Some Text that should only be included with foo {%- endfilter %} """ ) ) assert template.render(cookiecutter=dict(include_foo=True)) == snick.dedent( """ Some Text that should always be included Some Text that should only be included with foo """ ) assert template.render(cookiecutter=dict(include_foo=False)) == snick.dedent( """ Some Text that should always be included """ )
def test_dedent__default(): indented_text = """ this is indented text it looks nice. I would like to remove leading space when I print it out """ expected_dedented_text = "\n".join([ "this is indented text", "it looks nice.", "I would like to remove", "leading space", "when I print it out", ]) assert snick.dedent(indented_text) == expected_dedented_text
def test_enboxify(): indented_unboxed_text = """ here's some text that we want to put into a box. That will make it look so very nice """ expected_boxed_text = snick.dedent(""" **************************** * here's some text that we * * want to put into a box. * * That will make it look * * so very nice * **************************** """) assert snick.enboxify(indented_unboxed_text) == expected_boxed_text
def test_dedent_all__default(): dedented_joined_text = snick.dedent_all( """ Here is the first blob with 8 spaces of indentation that should be dedented first. """, " Here is another single line with 2 spaces of indent.", "This line has no indentation.", ) assert dedented_joined_text == snick.dedent(""" Here is the first blob with 8 spaces of indentation that should be dedented first. Here is another single line with 2 spaces of indent. This line has no indentation. """)
def test_dedent__should_not_strip(): indented_text = """ this is indented text it looks nice. I would like to remove leading space when I print it out but not the leading and trailing newline. """ expected_dedented_text = "\n".join([ "\nthis is indented text", "it looks nice.", "I would like to remove", "leading space", "when I print it out", "but not the leading and trailing newline.\n", ]) assert snick.dedent(indented_text, should_strip=False) == expected_dedented_text
def test_pretty_format(): assert snick.pretty_format({ "a": { "b": 1, "c": { "d": 2 }, "e": 3 }, "f": 4 }) == snick.dedent(""" { 'a': { 'b': 1, 'c': { 'd': 2, }, 'e': 3, }, 'f': 4, } """)