Skip to content

Commit

Permalink
Allow to call the root() BQL function with only one argument
Browse files Browse the repository at this point in the history
Make the second argument default to 1.
  • Loading branch information
dnicolodi committed Jun 10, 2024
1 parent e39b7d7 commit 5625b83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion beanquery/query_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ def today():

# Operations on accounts.

@function([str], str)
@function([str, int], str)
def root(acc, n):
def root(acc, n=1):
"""Get the root name(s) of the account."""
return account.root(n, acc)

Expand Down
5 changes: 5 additions & 0 deletions beanquery/query_env_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ def test_interval(self):
self.assertResult('interval("1 baz")', None)
self.assertResult('interval("A days")', None)

def test_root(self):
self.assertResult('root("Assets:Foo:Bar", 2)', 'Assets:Foo')
self.assertResult('root("Assets:Foo:Bar", 1)', 'Assets')
self.assertResult('root("Assets:Foo:Bar")', 'Assets')

def test_func_meta(self):
# use the loader to have the pad transaction inserted
entries, _, options = loader.load_string('''
Expand Down

0 comments on commit 5625b83

Please sign in to comment.