예제 #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
예제 #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
예제 #3
0
class Sources:

    TAKEOUT = Source(index_takeout, name='takeout')

    PLAIN = Source(
        shellcmd.index,
        extract_from_path('tests/testdata/custom'),
        name='test',
    )
예제 #4
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
예제 #5
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'
예제 #6
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',
            }
예제 #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