Exemple #1
0
def test_find_source_prefers_nearer_parent_with_source(source_finder):
    self = block('self')
    parent = block('parent', self)
    grandparent = block('grandparent with source', parent)
    great_grandparent = block('great grandparent with source', grandparent)

    source = source_finder(self, [great_grandparent, grandparent, parent])

    assert source == 'grandparent with source'
Exemple #2
0
def test_find_source_ignores_siblings_with_source(source_finder):
    self = block('self')
    parent = block(
        'parent without source',
        block('earlier sibling with source'),
        self,
        block('later sibling with source'),
    )

    assert source_finder(self, [parent]) is None
Exemple #3
0
def test_source_builder(source_builder, mock_source_finder,
                        mock_source_formatter):
    child_block_json = block('child')
    parent_block_json = block('parent', child_block_json)
    page_json = page(parent_block_json)

    (when(mock_source_finder).called_with(
        child_block_json,
        [page_json, parent_block_json]).then_return('found source'))

    (when(mock_source_formatter).called_with(
        child_block_json, 'found source',
        page_json).then_return('formatted source'))

    formatted_source = source_builder(child_block_json,
                                      [page_json, parent_block_json])

    assert formatted_source == 'formatted source'
Exemple #4
0
def test_format_as_html(
        roam_json_file, anki_note_importer, anki_model_notes,
):
    roam_json_file.write_json([page(
        block(
            '{<cloze> } &  text ',
            block('source:: source  & '),
        ),
        title=' &  title ',
    )])

    info = anki_note_importer.import_from_path(str(roam_json_file.path))

    anki_model_notes.add_note.assert_has_calls([
        call(AnkiNote(
            content='{{c1::&lt;cloze&gt; }} &amp;&nbsp;&nbsp;text ',
            source="source&nbsp;&nbsp;&amp;<br>Note from Roam page &#x27; &amp;&nbsp;&nbsp;title &#x27;.",
        )),
    ])
    assert info == '1 new notes imported.'
Exemple #5
0
def test_import_cloze_note_with_source(
    roam_json_file, addon_data, anki_collection, anki_model_notes,
):
    roam_json_file.write_json([page(
        block(
            '{cloze} text',
            block('source:: reference'),
        ),
        title='title',
    )])

    importer = AnkiNoteImporter(addon_data, anki_collection)
    info = importer.import_from_path(str(roam_json_file.path))

    anki_model_notes.add_note.assert_has_calls([
        call(AnkiNote(
            content='{{c1::cloze}} text',
            source="reference<br>Note from Roam page &#x27;title&#x27;.",
        )),
    ])
    assert info == '1 new notes imported.'
Exemple #6
0
def test_format_source(source_formatter, mock_time_formatter):
    create_time = 1337
    edit_time = 31337
    page_json = page(title='title')
    block_json = block('note', create_time=create_time, edit_time=edit_time)
    (when(mock_time_formatter).called_with(create_time).then_return(
        '[create time]'))
    (when(mock_time_formatter).called_with(edit_time).then_return(
        '[edit time]'))

    formatted_source = source_formatter(block_json, '[source]', page_json)

    assert formatted_source == "[source]\nNote from Roam page 'title', created at [create time], edited at [edit time]."
Exemple #7
0
def test_find_source_prefers_first_child_with_source_to_parent(
    source_finder, ):
    self = block(
        'self',
        block('first child'),
        block('first child with source'),
        block('second child with source'),
    )
    parent = block(
        'parent with source',
        block('earlier sibling with source'),
        self,
        block('later sibling with source'),
    )

    assert source_finder(self, [parent]) == 'first child with source'
Exemple #8
0
def test_find_source_ignores_grandchildren(source_finder):
    grandchild = block('grandchild with source')
    child = block('child', grandchild)
    self = block('self', child)

    assert source_finder(self, []) is None
Exemple #9
0
def test_source_extractor_with_extra_text(source_extractor):
    block_json = block('text source: reference ')
    assert source_extractor(block_json) is None
Exemple #10
0
def test_source_extractor_with_extra_whitespace(source_extractor):
    block_json = block('  Source  :  :  reference  ')
    assert source_extractor(block_json) == 'reference'
Exemple #11
0
def test_source_extractor_with_one_colon(source_extractor):
    block_json = block('Source: reference')
    assert source_extractor(block_json) == 'reference'
Exemple #12
0
def test_source_extractor_with_lower_case_source(source_extractor):
    block_json = block('source:: reference')
    assert source_extractor(block_json) == 'reference'