Exemplo n.º 1
0
def test_url_heading():
    org = Org.from_string("""
* [2016-05-14 Sat 15:33] [[https://www.reddit.com/r/androidapps/comments/4i36z9/how_you_use_your_android_to_the_maximum/d2uq24i][sc4s2cg comments on How you use your android to the maximum?]] :android:
    """)

    assert org.children[
        0].heading == '[[https://www.reddit.com/r/androidapps/comments/4i36z9/how_you_use_your_android_to_the_maximum/d2uq24i][sc4s2cg comments on How you use your android to the maximum?]]'
Exemplo n.º 2
0
def test_broken_tags():
    org = Org.from_string("""
* [2018-07-11 Wed 21:14] for some reasong there is a newline before tags :( 
  :social:talking:

    """)
    assert len(org.firstlevel()) == 1
Exemplo n.º 3
0
def test_dates():
    org = Org.from_string(ORG)

    cc = find(org, 'something')
    assert cc.properties == {'CREATED': '[2018-10-23 Tue 20:55]'}
    assert cc.created == datetime(year=2018,
                                  month=10,
                                  day=23,
                                  hour=20,
                                  minute=55)

    cc2 = find(org, 'etc')
    assert cc2.created is None

    cc3 = find(org, 'note-with-implicit-date')
    assert cc3.created == datetime(year=2018,
                                   month=10,
                                   day=11,
                                   hour=20,
                                   minute=55)

    cc4 = find(org, 'messed-up')
    assert cc4.created is not None

    cc5 = match(org, 'from-kindle')
    cc6 = match(org, 'Your Highlight on page 153')
    cc7 = match(org, 'Your Highlight on Location')
Exemplo n.º 4
0
def test_tags():
    org = Org.from_string(ORG)

    res = org.with_tag('kindle', with_inherited=False)
    assert len(res) == 1

    res = org.with_tag('kindle', with_inherited=True)
    assert len(res) == 2
Exemplo n.º 5
0
def test_single():
    o = """
* hello
"""
    org = Org.from_string(o)

    entries = org.xpath_all('//org')

    assert len(entries) == 1
Exemplo n.º 6
0
def test_active_created():
    org = Org.from_string("""
* TODO <2017-11-29 Wed 22:24> something :taggg:
    """)
    [res] = org.with_tag('taggg')
    assert res.created == datetime(year=2017,
                                   month=11,
                                   day=29,
                                   hour=22,
                                   minute=24)
Exemplo n.º 7
0
def test_root_xpath():
    org = Org.from_string(_root_org)
    root = org.xpath('//root')
    assert root == org

    orgs = org.xpath_all('//org')
    assert len(orgs) == 3

    # TODO ugh. need to do something like that?...
    rc = org.firstlevel()
    assert len(rc) == 3
Exemplo n.º 8
0
def test_bad_date():
    org = Org.from_string("""
* [#B] [2018-08-21 Tue 22:35] uu [1234 01234567] :hello:
""")
    res = org.with_tag('hello')
    assert len(res) == 1
    assert res[0].created == datetime(year=2018,
                                      month=8,
                                      day=21,
                                      hour=22,
                                      minute=35)
Exemplo n.º 9
0
def test_empty_heading():
    org = Org.from_string("""
* [2019-05-26 Sun 09:11]                                            :hello:

abacaba

** TODO database
 :PROPERTIES:
 :CREATED:  [2019-05-26 Sun 09:15]
 :END:
""")
    c = org.children[0]
    assert c.heading == ''
    assert c.tags == {'hello'}

    cc = c.children[0]
    assert cc.heading == 'database'
Exemplo n.º 10
0
def test_table_xpath():
    o = """
| table | a |
|-------+---|
| xxx   | 1 |
    """
    org = Org.from_string(o)

    contents = org.contents
    assert len(contents) == 3  # TODO careful about empty line handling..
    assert isinstance(contents[1], OrgTable)

    # TODO ugh... it's cause it's conflict between table as a field and table as class name...
    # ugh. how to make it consistent?..
    tentry = org.xpath("//table")

    assert isinstance(tentry, OrgTable)
Exemplo n.º 11
0
def test_root():
    org = Org.from_string(_root_org)

    assert org.heading == ''
    assert org.tags == {'whatever', 'tag2'}
    assert org.self_tags == {'whatever', 'tag2'}
    assert org.file_settings == {'FILETAGS': [':whatever:tag2:']}

    # TODO not so sure about including filetags...
    # TODO what semantics does heading have for root node??
    assert org.get_raw(recursive=False) == """
#+FILETAGS: :whatever:tag2:

top""".lstrip()
    assert len(org.children) == 3
    assert [c.heading for c in org.children] == ['note1', 'note2', 'note3']
    assert org.level == 0
Exemplo n.º 12
0
def test_gh():
    # covers https://github.com/tkf/orgparse/issues/1, just in case..
    org = Org.from_string("""
* H1
** H2
*** H3
* H4
** H5
    """)
    [h1, h4] = org.children
    [h2] = h1.children
    [h3] = h2.children
    [h5] = h4.children
    assert h1.heading == 'H1'
    assert h2.heading == 'H2'
    assert h3.heading == 'H3'
    assert h4.heading == 'H4'
    assert h5.heading == 'H5'
Exemplo n.º 13
0
def cross_trainer_data():
    # FIXME some manual entries in python
    # I guess just convert them to org

    from porg import Org
    # FIXME should use all org notes and just query from them?
    wlog = Org.from_file(config.workout_log)
    cross_table = wlog.xpath('//org[heading="Cross training"]//table')

    def maybe(f):
        def parse(s):
            if len(s) == 0:
                return None
            return f(s)

        return parse

    def parse_mm_ss(x: str) -> timedelta:
        hs, ms = x.split(':')
        return timedelta(seconds=int(hs) * 60 + int(ms))

    # todo eh. not sure if there is a way of getting around writing code...
    # I guess would be nice to have a means of specifying type in the column? maybe multirow column names??
    # need to look up org-mode standard..
    from ...core.orgmode import parse_org_datetime
    mappers = {
        'duration': lambda s: parse_mm_ss(s),
        'date': lambda s: tzify(parse_org_datetime(s)),
        'comment': str,
    }
    for row in cross_table.lines:
        # todo make more defensive, fallback on nan for individual fields??
        try:
            d = {}
            for k, v in row.items():
                # todo have something smarter... e.g. allow pandas to infer the type??
                mapper = mappers.get(k, maybe(float))
                d[k] = mapper(v)  # type: ignore[operator]
            yield d
        except Exception as e:
            # todo add parsing context
            yield {'error': str(e)}
Exemplo n.º 14
0
def test_raw():
    org = Org.from_string("""
* [2018-12-02 Sun 13:00] alala :wlog:
uu
** 7
hello
** 6
** 4""")
    note = org.children[0]
    assert note.heading == 'alala'
    assert note.get_raw(heading=False, recursive=True) == '''
uu
** 7
hello
** 6
** 4
'''.strip()
    assert note.created == datetime(year=2018,
                                    month=12,
                                    day=2,
                                    hour=13,
                                    minute=0)
Exemplo n.º 15
0
def test_table_xpath_2():
    org = Org.from_string("""
* item

#+tblname: something
| date                 | value | comment                       |
|----------------------+-------+-------------------------------|
| 14.04.17             |  11   | aaaa                          |
| May 26 2017 08:00    |  12   | what + about + pluses?        |
| May 26 09:00 - 10:00 |  13   | time is                       |

    some comment

#+BEGIN_SRC python :var fname="plot.png" :var table=something :results file
fig.savefig(fname)
return fname
#+END_SRC

#+RESULTS:
[[file:plot.png]]
""")
    tbl = org.xpath('//org//table')
    assert isinstance(tbl, OrgTable)
Exemplo n.º 16
0
def test_logbook():
    org = Org.from_string("""
* TODO [#C] this broke my parser
  :LOGBOOK:
  CLOCK: [2018-01-24 Wed 19:20]--[2018-01-24 Wed 21:00] =>  1:40
  :END:
some content...

* START [#C] or did that broke??
SCHEDULED: <2018-11-08 Thu>
:PROPERTIES:
:CREATED:  [2018-02-04 Sun 20:37]
:END:
:LOGBOOK:
CLOCK: [2018-05-01 Tue 20:00]--[2018-05-01 Tue 20:59] =>  0:59
:END:

waat
    """)

    res = org.xpath_all("//org")

    for r in res:
        r.heading
Exemplo n.º 17
0
def find(org: Org, heading: str):
    [node] = ([n for n in org.iterate() if n.heading == heading])
    return node
Exemplo n.º 18
0
def _load_test_file(name: str) -> Org:
    return Org.from_file(Path(__file__).parent / 'data' / name)
Exemplo n.º 19
0
def test_1111():
    org = Org.from_string("""
* qm test http://www.quantified-mind.com/lab/take_tests/6156220345354
    """)
    for x in org.iterate():
        assert x.created is None
Exemplo n.º 20
0
def match(org: Org, hpart: str):
    [node] = ([n for n in org.iterate() if hpart in n.heading])
    return node
Exemplo n.º 21
0
 def query_all(self, query):
     for of in self.files:
         org = Org.from_file(str(of))
         yield from query(org)
Exemplo n.º 22
0
 def query_all(self, query):
     res: List[Org] = []
     for of in self.files:
         org = Org.from_file(str(of))
         res.extend(query(org))
     return res
Exemplo n.º 23
0
 def _iterate(self, f: Path) -> Iterable[OrgNote]:
     o = Org.from_file(f)
     for x in o.iterate():
         yield to_note(x)