Beispiel #1
0
def test_filter():
    import promnesia.sources.shellcmd as custom_gen
    from promnesia.sources.plaintext import extract_from_path

    History.add_filter(r'some-weird-domain')
    hist = custom_gen.get_custom_history(extract_from_path(tdata('custom')), )
    assert len(hist) == 4  # chrome-error got filtered out
Beispiel #2
0
def test_filter() -> None:
    import promnesia.sources.shellcmd as custom_gen
    from promnesia.sources.plaintext import extract_from_path

    # ugh... such a mess
    @contextmanager
    def reset_filters():
        try:
            E.filters.cache_clear()
            yield
        finally:
            E.filters.cache_clear()

    import promnesia.extract as E
    with reset_filters(), with_config('''
FILTERS = [
    "some-weird-domain.xyz"
]
'''):
        visits = as_visits(
            W(
                custom_gen.index,
                extract_from_path(tdata('custom')),
            ))
        assert len(visits) == 4
Beispiel #3
0
def test_heading():
    items = list(extract_from_file(tdata('auto/orgs/file2.org')))
    assert {i.url for i in items} == {
        'https://en.wikipedia.org/wiki/Computational_topology',
        'http://graphics.stanford.edu/courses/cs468-09-fall/',
        'https://en.wikipedia.org/wiki/Triangulation_(topology)',
        'https://en.wikipedia.org/wiki/Digital_manifold',
    }
Beispiel #4
0
def test_org_indexer_2():
    items = list(extract_from_file(tdata('auto/orgs/file3.org')))

    assert len(items) == 6
    for i in items:
        assert i.dt.tzinfo is None, i
    assert items[0].url == 'https://www.reddit.com/r/androidapps/comments/4i36z9/how_you_use_your_android_to_the_maximum/d2uq24i'
    assert items[1].url == 'https://link.com'
    assert items[-2].url == 'https://en.wikipedia.org/wiki/Resilio_Sync'
def test_url_in_properties() -> None:
    items = [
        v if isinstance(v, Visit) else throw(v)
        for v in extract_from_file(tdata('auto/orgs/file4.org'))
    ]

    assert len(items) == 2, items
    assert items[0].url == 'https://example.org/ref_example'
    assert items[1].url == 'http://example.org/a_test'
Beispiel #6
0
def test_json():
    mm = makemap(auto.index(tdata('auto/pocket.json')))
    assert mm.keys() == _JSON_URLS

    # TODO not sure if they deserve separate visits..
    [v1, v2] = mm[sa2464]
    assert v1.context == 'list::yyy::given_url'
    assert v1.locator.href.startswith('editor://')
    assert v1.locator.href.endswith('pocket.json')
Beispiel #7
0
def test_plaintext_path_extractor():
    import promnesia.sources.shellcmd as custom_gen
    from promnesia.sources.plaintext import extract_from_path

    visits = history(W(
        custom_gen.index,
        extract_from_path(tdata('custom')),
    ))
    assert {v.orig_url
            for v in visits} == {
                'http://google.com',
                'http://google.com/',
                'http://some-weird-domain/whatever',
                'https://google.com',
                'http://what.about.this.link',
            }

    [wa] = [v for v in visits if v.orig_url == 'http://what.about.this.link']
    f2 = Path(tdata('custom')) / 'file2.txt'
    assert wa.locator.href == f'editor://{f2}:3'  # occurs line 3
def test_org_indexer_2() -> None:
    items = [
        v if isinstance(v, Visit) else throw(v)
        for v in extract_from_file(tdata('auto/orgs/file3.org'))
    ]

    assert len(items) == 6
    assert items[
        0].url == 'https://www.reddit.com/r/androidapps/comments/4i36z9/how_you_use_your_android_to_the_maximum/d2uq24i'
    assert items[1].url == 'https://link.com'
    assert items[-2].url == 'https://en.wikipedia.org/wiki/Resilio_Sync'
Beispiel #9
0
def test_custom():
    import promnesia.sources.shellcmd as custom_gen

    hist = history(
        W(
            custom_gen.index,
            """grep -Eo -r --no-filename '(http|https)://\S+' """ +
            tdata('custom'),
        ))
    # TODO I guess filtering of equivalent urls should rather be tested on something having context (e.g. org mode)
    assert len(hist) == 5
Beispiel #10
0
def test_heading() -> None:
    items = [
        v if isinstance(v, Visit) else throw(v)
        for v in extract_from_file(tdata('auto/orgs/file2.org'))
    ]
    assert {i.url
            for i in items} == {
                'https://en.wikipedia.org/wiki/Computational_topology',
                'http://graphics.stanford.edu/courses/cs468-09-fall/',
                'https://en.wikipedia.org/wiki/Triangulation_(topology)',
                'https://en.wikipedia.org/wiki/Digital_manifold',
            }
Beispiel #11
0
def test_custom() -> None:
    import promnesia.sources.shellcmd as custom_gen

    visits = as_visits(
        W(
            custom_gen.index,
            # meh. maybe should deprecate plain string here...
            """grep -Eo -r --no-filename (http|https)://\S+ """ +
            tdata('custom'),
        ))
    # TODO I guess filtering of equivalent urls should rather be tested on something having context (e.g. org mode)
    assert len(visits) == 5
Beispiel #12
0
def test_auto() -> None:
    mm = makemap(auto.index(tdata('auto')))
    org_link = 'https://www.youtube.com/watch?v=rHIkrotSwcc'
    assert {
        *_JSON_URLS,
        org_link,
    }.issubset(mm.keys())

    [v] = mm[org_link]
    assert v.locator.title == 'orgs' + os.sep + 'file.org:14'  # meh
    assert v.locator.href.endswith('file.org:14')
    assert "xxx /r/cpp" in v.context
    assert "I've enjoyed [Chandler Carruth's" in v.context
Beispiel #13
0
def test_json() -> None:
    mm = makemap(auto.index(
        tdata('auto'),
        ignored='*/orgs/*',
    ))
    assert mm.keys() == _JSON_URLS

    # TODO not sure if they deserve separate visits..
    [v1, v2] = mm[sa2464]
    assert v1.context == 'list::yyy::given_url'
    # todo not sure if editor:// work on Windows
    assert v1.locator.href.startswith('editor://')
    assert v1.locator.href.endswith('pocket.json')
Beispiel #14
0
def test_normalise_weird():
    import promnesia.sources.shellcmd as custom_gen
    from promnesia.sources.plaintext import extract_from_path

    visits = history(
        W(
            custom_gen.index,
            extract_from_path(tdata('weird.txt')),
        ))
    norms = {v.norm_url for v in visits}

    # TODO assert there are no spaces in the database?
    assert "urbandictionary.com/define.php?term=Belgian%20Whistle" in norms
    assert "en.wikipedia.org/wiki/Dinic%27s_algorithm" in norms
Beispiel #15
0
def test_auto():
    mm = makemap(auto.index(tdata('auto')))
    org_link = 'https://www.youtube.com/watch?v=rHIkrotSwcc'
    assert {
        *_JSON_URLS,
        org_link,
    }.issubset(mm.keys())

    [v] = mm[org_link]
    assert v.locator.title == 'orgs/file.org'
    assert v.locator.href.endswith(
        'file.org')  # TODO link number or jump to heading?
    assert "xxx /r/cpp" in v.context
    assert "I've enjoyed [Chandler Carruth's" in v.context
Beispiel #16
0
def test_org_indexer():
    items = list(extract_from_file(tdata('auto/orgs/file.org')))
    assert len(items) == 3

    cpp = items[1]
    assert cpp.url == 'https://www.youtube.com/watch?v=rHIkrotSwcc'
    # TODO not sure about filetags?
    assert cpp.context == '''
xxx /r/cpp   :cpp:programming:
 I've enjoyed [Chandler Carruth's _There Are No Zero-cost Abstractions_](
 https://www.youtube.com/watch?v=rHIkrotSwcc) very much.

'''.lstrip()

    cozy = items[2]
    assert cozy.url == 'https://twitter.com/Mappletons/status/1255221220263563269'
Beispiel #17
0
def test_org_indexer() -> None:
    [_, cpp, cozy] = [
        v if isinstance(v, Visit) else throw(v)
        for v in extract_from_file(tdata('auto/orgs/file.org'))
    ]

    assert cpp.url == 'https://www.youtube.com/watch?v=rHIkrotSwcc'
    # TODO not sure about filetags?
    assert cpp.context == '''
xxx /r/cpp   :cpp:programming:
 I've enjoyed [Chandler Carruth's _There Are No Zero-cost Abstractions_](
 https://www.youtube.com/watch?v=rHIkrotSwcc) very much.

'''.lstrip()

    assert cozy.url == 'https://twitter.com/Mappletons/status/1255221220263563269'
Beispiel #18
0
def test_normalise_weird() -> None:
    import promnesia.sources.shellcmd as custom_gen
    from promnesia.sources.plaintext import extract_from_path

    visits = as_ok_visits(
        W(
            custom_gen.index,
            extract_from_path(tdata('weird.txt')),
        ))
    [v1, v2] = visits

    # TODO assert there are no spaces in the database?
    assert "urbandictionary.com/define.php?term=Belgian%20Whistle" == v1.norm_url

    assert "en.wikipedia.org/wiki/Dinic%27s_algorithm" == v2.norm_url
    assert v2.locator.title.endswith('weird.txt:2')
    assert v2.context == 'right, so https://en.wikipedia.org/wiki/Dinic%27s_algorithm can be used for max flow'
Beispiel #19
0
def test_normalise() -> None:
    import promnesia.sources.shellcmd as custom_gen
    from promnesia.sources.plaintext import extract_from_path

    visits = as_ok_visits(
        W(
            custom_gen.index,
            extract_from_path(tdata('normalise')),
        ))
    assert len(visits) == 7
    assert {v.norm_url
            for v in visits} == {
                'hi.com',
                'reddit.com/post',
                'argos.co.uk/webapp/wcs/stores/servlet/OrderItemDisplay',
                'youtube.com/watch?v=XXlZfc1TrD0',
                'youtube.com/watch?v=XXlZfc1Tr11',
            }
Beispiel #20
0
def _test_helper(tmp_path):
    tdir = Path(tmp_path)
    cache_dir = tdir / 'cache'
    cache_dir.mkdir()

    # TODO extract that into index_takeout?
    # TODO ugh. quite hacky...
    template_config = tdata('test_config.py')
    copy(template_config, tdir)
    config = tdir / 'test_config.py'
    with config.open('a') as fo:
        fo.write(f"""
OUTPUT_DIR = '{tdir}'
CACHE_DIR  = '{cache_dir}'
""")

    check_call(promnesia_bin('index', '--config', config))

    with wserver(db=tdir / 'promnesia.sqlite') as srv:
        yield srv
Beispiel #21
0
def test_obsidian() -> None:
    mm = makemap(auto.index(tdata('obsidian-vault')))
    example_url = 'https://example.com'
    [v] = mm[example_url]
    assert v.locator.href.startswith('obsidian://')
Beispiel #22
0
 class user_config:
     takeout_path = tdata('takeout-20150518T000000Z.zip')
Beispiel #23
0
 class user_config:
     takeout_path = tdata('takeout')
Beispiel #24
0
def test_logseq() -> None:
    mm = makemap(auto.index(tdata('logseq-graph')))
    example_url = 'https://example.com'
    [v] = mm[example_url]
    assert v.locator.href.startswith('logseq://')