Exemple #1
0
def test_code_yaml(mocker):
    """Test code block rendering with yaml language
    """
    mocker.patch.object(lookatme.config, "LOG")
    fake_config = mocker.patch.object(lookatme.render.pygments, "config")
    fake_config.STYLE = {
        "style": "monokai",
    }

    rendered = render_markdown("""
```yaml
test: a value
test2: "another value"
array:
  - item1
  - item2
  - item3
```""")

    stripped_rows = [
        b'',
        b'test: a value',
        b'test2: "another value"',
        b'array:',
        b'  - item1',
        b'  - item2',
        b'  - item3',
        b'',
    ]
    assert_render(stripped_rows, rendered)
Exemple #2
0
def test_table(mocker):
    """Test basic table rendering
    """
    import lookatme.widgets.table

    mocker.patch.object(lookatme.config, "LOG")
    fake_config = mocker.patch.object(lookatme.render.markdown_block, "config")
    mocker.patch.object(lookatme.widgets.table, "config", fake_config)
    fake_config.STYLE = {
        "table": {
            "column_spacing": 1,
            "header_divider": "-",
        },
    }

    rendered = render_markdown("""
| H1      |   H2   |     H3 |
|:--------|:------:|-------:|
| 1value1 | value2 | value3 |
| 1       | 2      | 3      |
""")

    stripped_rows = [
        b"H1        H2       H3",
        b"------- ------ ------",
        b"1value1 value2 value3",
        b"1          2        3",
    ]
    assert_render(stripped_rows, rendered, full_strip=True)
Exemple #3
0
def test_lists_with_newline(mocker):
    """Test list rendering with a newline between a new nested list and the
    previous list item
    """
    import lookatme.widgets.table

    mocker.patch.object(lookatme.config, "LOG")
    fake_config = mocker.patch.object(lookatme.render.markdown_block, "config")
    mocker.patch.object(lookatme.widgets.table, "config", fake_config)
    fake_config.STYLE = {
        "bullets": {
            "default": "*",
            "1": "-",
            "2": "=",
            "3": "^",
        },
    }

    rendered = render_markdown("""
* list 1

  * list 2
""")

    stripped_rows = [
        b'',
        b'  - list 1',
        b'',
        b'    = list 2',
        b'',
    ]
    assert_render(stripped_rows, rendered)
Exemple #4
0
def test_block_quote(mocker):
    """Test block quote rendering
    """
    mocker.patch.object(lookatme.config, "LOG")
    fake_config = mocker.patch.object(lookatme.render.markdown_block, "config")
    fake_config.STYLE = {
        "quote": {
            "style": {
                "fg": "",
                "bg": "",
            },
            "side": ">",
            "top_corner": "-",
            "bottom_corner": "=",
        },
    }

    rendered = render_markdown("""
> this is a quote
""")

    stripped_rows = [
        b'',
        b'-',
        b'>  this is a quote',
        b'=',
        b'',
    ]
    assert_render(stripped_rows, rendered)
Exemple #5
0
def test_file_loader_relative(tmpdir, mocker):
    """Test the built-in file loader extension
    """
    mocker.patch.object(lookatme.config, "LOG")
    mocker.patch.object(lookatme.config, "SLIDE_SOURCE_DIR", str(tmpdir))
    fake_config = mocker.patch.object(lookatme.render.markdown_block, "config")
    mocker.patch.object(lookatme.render.pygments, "config", fake_config)
    fake_config.STYLE = TEST_STYLE

    tmppath = tmpdir.join("test.py")
    tmppath.write("print('hello')")

    rendered = render_markdown(f"""
```file
path: test.py
relative: true
```
    """)

    stripped_rows = [
        b'',
        b"print('hello')",
        b'',
        b'',
        b'',
    ]
    assert_render(stripped_rows, rendered)
Exemple #6
0
def test_numbered_lists(mocker):
    """Test list rendering
    """
    import lookatme.widgets.table

    mocker.patch.object(lookatme.config, "LOG")
    fake_config = mocker.patch.object(lookatme.render.markdown_block, "config")
    mocker.patch.object(lookatme.widgets.table, "config", fake_config)
    fake_config.STYLE = {
        "bullets": {
            "default": "*",
            "1": "-",
            "2": "=",
            "3": "^",
        },
        "numbering": {
            "default": "numeric",
            "1": "numeric",
            "2": "alpha",
            "3": "roman",
        },
    }

    rendered = render_markdown("""
1. list 1
    1. alpha1
    1. alpha2
    1. alpha3
1. list 2
    1. alpha1.1
        1. roman1
        1. roman2
        1. roman3
    1. alpha1.2
        * test1
        * test2
1. list 3
""")

    stripped_rows = [
        b'',
        b'  1. list 1',
        b'     a. alpha1',
        b'     b. alpha2',
        b'     c. alpha3',
        b'  2. list 2',
        b'     a. alpha1.1',
        b'        i.   roman1',
        b'        ii.  roman2',
        b'        iii. roman3',
        b'     b. alpha1.2',
        b'        ^ test1',
        b'        ^ test2',
        b'  3. list 3',
        b'',
    ]
    assert_render(stripped_rows, rendered)
Exemple #7
0
def test_lists(mocker):
    """Test list rendering
    """
    import lookatme.widgets.table

    mocker.patch.object(lookatme.config, "LOG")
    fake_config = mocker.patch.object(lookatme.render.markdown_block, "config")
    mocker.patch.object(lookatme.widgets.table, "config", fake_config)
    fake_config.STYLE = {
        "bullets": {
            "default": "*",
            "1": "-",
            "2": "=",
            "3": "^",
        },
    }

    rendered = render_markdown("""
* list 1
  * list 2
    * list 3
      * list 4
  * list 2
    * list 3
    * list 3

* list 2
""")

    stripped_rows = [
        b'',
        b'  - list 1',
        b'    = list 2',
        b'      ^ list 3',
        b'        * list 4',
        b'    = list 2',
        b'      ^ list 3',
        b'      ^ list 3',
        b'  - list 2',
        b'',
    ]
    assert_render(stripped_rows, rendered)
Exemple #8
0
def test_code(mocker):
    """Test code block rendering
    """
    mocker.patch.object(lookatme.config, "LOG")
    fake_config = mocker.patch.object(lookatme.render.pygments, "config")
    fake_config.STYLE = {
        "style": "monokai",
    }

    rendered = render_markdown("""
```python
def some_fn(*args, **kargs):
    pass```
""")

    stripped_rows = [
        b'',
        b'def some_fn(*args, **kargs):',
        b'    pass',
        b'',
    ]
    assert_render(stripped_rows, rendered)
Exemple #9
0
def test_hrule(mocker):
    """Test that hrules render correctly
    """
    mocker.patch.object(lookatme.config, "LOG")
    fake_config = mocker.patch.object(lookatme.render.markdown_block, "config")
    fake_config.STYLE = {
        "hrule": {
            "style": {
                "fg": "",
                "bg": "",
            },
            "char": "=",
        },
    }

    rendered = render_markdown("---", width=10, single_slide=True)
    stripped_rows = [
        b'',
        b'==========',
        b'',
    ]
    assert_render(stripped_rows, rendered)
Exemple #10
0
def test_file_loader_not_found(mocker):
    """Test the built-in file loader extension
    """
    mocker.patch.object(lookatme.config, "LOG")
    fake_config = mocker.patch.object(lookatme.render.markdown_block, "config")
    mocker.patch.object(lookatme.render.pygments, "config", fake_config)
    fake_config.STYLE = TEST_STYLE

    rendered = render_markdown(f"""
```file
path: does_not_exist.py
```
    """)

    stripped_rows = [
        b'',
        b"File not found",
        b'',
        b'',
        b'',
    ]
    assert_render(stripped_rows, rendered)
Exemple #11
0
def test_headings(mocker):
    """Test basic header rendering
    """
    mocker.patch.object(lookatme.config, "LOG")
    fake_config = mocker.patch.object(lookatme.render.markdown_block, "config")
    fake_config.STYLE = TEST_STYLE

    rendered = render_markdown("""
# H1
## H2
### H3
---
""")

    stripped_rows = [
        b"",
        b"|H1|",
        b"",
        b"|H2|",
        b"",
        b"|H3|",
        b"",
    ]
    assert_render(stripped_rows, rendered)
Exemple #12
0
def test_file_loader_with_transform(tmpdir, mocker):
    """Test the built-in file loader extension
    """
    mocker.patch.object(lookatme.config, "LOG")
    fake_config = mocker.patch.object(lookatme.render.markdown_block, "config")
    mocker.patch.object(lookatme.render.pygments, "config", fake_config)
    fake_config.STYLE = TEST_STYLE

    tmppath = tmpdir.join("test.py")
    tmppath.write("""
Hello
Apples2
there
Apples3
there
Apples1
""")

    rendered = render_markdown(f"""
```file
path: {tmppath}
relative: false
transform: "grep -i apples | sort"
```
    """)

    stripped_rows = [
        b'',
        b"Apples1",
        b'Apples2',
        b'Apples3',
        b'',
        b'',
        b'',
    ]
    assert_render(stripped_rows, rendered)