Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
ptbcli
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Daniele Nicolodi
ptbcli
Commits
21371b1c
Commit
21371b1c
authored
3 years ago
by
Daniele Nicolodi
Browse files
Options
Downloads
Patches
Plain Diff
tests: Some tests for beanutils
parent
cce357e8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_beanutils.py
+108
-0
108 additions, 0 deletions
tests/test_beanutils.py
with
108 additions
and
0 deletions
tests/test_beanutils.py
0 → 100644
+
108
−
0
View file @
21371b1c
import
io
import
textwrap
import
unittest
import
beanutils
import
orders
from
beancount.parser
import
parser
def
parse
(
x
):
entries
,
errors
,
options
=
parser
.
parse_string
(
textwrap
.
dedent
(
x
))
assert
not
errors
return
entries
class
TestMerge
(
unittest
.
TestCase
):
def
assertMetadata
(
self
,
entry
,
value
):
meta
=
{
k
:
v
for
k
,
v
in
entry
.
meta
.
items
()
if
k
not
in
(
'
filename
'
,
'
lineno
'
)}
self
.
assertEqual
(
meta
,
value
)
def
assertPostingAccounts
(
self
,
entry
,
value
):
accounts
=
{
p
.
account
for
p
in
entry
.
postings
}
self
.
assertEqual
(
accounts
,
value
)
def
test_merge_simple
(
self
):
existing
=
parse
(
"""
2021-01-01 !
"
Test
"
alpha:
"
a
"
beta:
"
b
"
Assets:Cash -2.00 USD
Expenses:Test
"""
)
entries
=
parse
(
"""
2021-01-02 *
"
New
"
alpha:
"
a
"
new:
"
new
"
Assets:Cash -2.00 USD
Expenses:Test
"""
)
r
=
orders
.
merge_entries
(
existing
,
entries
)
self
.
assertEqual
(
len
(
r
),
2
)
self
.
assertMetadata
(
r
[
0
],
{
'
alpha
'
:
'
a
'
,
'
beta
'
:
'
b
'
,
'
__duplicate__
'
:
True
})
self
.
assertMetadata
(
r
[
1
],
{
'
alpha
'
:
'
a
'
,
'
beta
'
:
'
b
'
,
'
new
'
:
'
new
'
})
self
.
assertEqual
(
r
[
1
].
narration
,
'
Test
'
)
self
.
assertPostingAccounts
(
r
[
1
],
{
'
Assets:Cash
'
,
'
Expenses:Test
'
})
def
test_merge_postings
(
self
):
existing
=
parse
(
"""
2021-01-01 !
"
Test
"
alpha:
"
a
"
beta:
"
b
"
Assets:Cash -2.00 USD
Expenses:Test
"""
)
entries
=
parse
(
"""
2021-01-02 *
"
New
"
alpha:
"
a
"
new:
"
new
"
Assets:Cash -2.00 USD
"""
)
r
=
orders
.
merge_entries
(
existing
,
entries
)
self
.
assertPostingAccounts
(
r
[
1
],
{
'
Assets:Cash
'
,
'
Expenses:Test
'
})
class
TestPrinter
(
unittest
.
TestCase
):
def
test_printer
(
self
):
entries
=
parse
(
"""
2021-01-01 *
"
Example
"
Expenses:Foo 1.00 USD
Expenses:Bar 100.00 USD
Assets:Cash
2021-01-01 *
"
Example
"
Expenses:Foo 1.00 USD
Expenses:Bar 1.00 USD
2021-01-01 *
"
Example
"
Expenses:Foo 100.00 USD
Assets:Cash
2021-01-01 *
"
Example
"
Expenses:Foo 100.00 CAD @ 1.10 USD
Assets:Cash
"""
)
entries
[
1
].
meta
[
'
__duplicate__
'
]
=
True
out
=
io
.
StringIO
()
beanutils
.
print_entries
(
entries
,
out
)
self
.
assertEqual
(
out
.
getvalue
(),
textwrap
.
dedent
(
"""
2021-01-01 *
"
Example
"
Expenses:Foo 1.00 USD
Expenses:Bar 100.00 USD
Assets:Cash
; 2021-01-01 *
"
Example
"
; Expenses:Foo 1.00 USD
; Expenses:Bar 1.00 USD
2021-01-01 *
"
Example
"
Expenses:Foo 100.00 USD
Assets:Cash
2021-01-01 *
"
Example
"
Expenses:Foo 100.00 CAD @ 1.10 USD
Assets:Cash
"""
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment