Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def format_date(date):
"""Format a date according to the current interval."""
if g.interval is Interval.YEAR:
return date.strftime("%Y")
if g.interval is Interval.QUARTER:
return "{}Q{}".format(date.year, (date.month - 1) // 3 + 1)
if g.interval is Interval.MONTH:
return date.strftime("%b %Y")
if g.interval is Interval.WEEK:
return date.strftime("%YW%W")
if g.interval is Interval.DAY:
return date.strftime("%Y-%m-%d")
return ""
def format_date(date):
"""Format a date according to the current interval."""
if g.interval is Interval.YEAR:
return date.strftime("%Y")
if g.interval is Interval.QUARTER:
return "{}Q{}".format(date.year, (date.month - 1) // 3 + 1)
if g.interval is Interval.MONTH:
return date.strftime("%b %Y")
if g.interval is Interval.WEEK:
return date.strftime("%YW%W")
if g.interval is Interval.DAY:
return date.strftime("%Y-%m-%d")
return ""
def test_add_inventory():
inv = CounterInventory()
inv2 = CounterInventory()
inv3 = CounterInventory()
inv.add_amount(A("10 USD"))
inv2.add_amount(A("30 USD"))
inv3.add_amount(A("-40 USD"))
inv.add_inventory(inv2)
assert len(inv) == 1
inv.add_inventory(inv3)
assert inv.is_empty()
inv = CounterInventory()
inv.add_inventory(inv2)
assert len(inv) == 1
def test_add_inventory():
inv = CounterInventory()
inv2 = CounterInventory()
inv3 = CounterInventory()
inv.add_amount(A("10 USD"))
inv2.add_amount(A("30 USD"))
inv3.add_amount(A("-40 USD"))
inv.add_inventory(inv2)
assert len(inv) == 1
inv.add_inventory(inv3)
assert inv.is_empty()
inv = CounterInventory()
inv.add_inventory(inv2)
assert len(inv) == 1
def test_add_amount():
inv = CounterInventory()
inv.add_amount(A("10 USD"))
inv.add_amount(A("30 USD"))
assert len(inv) == 1
inv.add_amount(A("-40 USD"))
assert inv.is_empty()
inv.add_amount(A("10 USD"))
inv.add_amount(A("20 CAD"))
inv.add_amount(A("10 USD"))
assert len(inv) == 2
inv.add_amount(A("-20 CAD"))
assert len(inv) == 1
def test_should_show(app):
with app.test_request_context("/"):
app.preprocess_request()
assert should_show(g.ledger.root_tree.get("")) is True
assert should_show(g.ledger.root_tree.get("Expenses")) is True
account = TreeNode("name")
assert should_show(account) is False
account.balance_children = CounterInventory({("USD", None): 9})
assert should_show(account) is True
with app.test_request_context("/?time=2100"):
app.preprocess_request()
assert not g.ledger.fava_options["show-accounts-with-zero-balance"]
assert should_show(g.ledger.root_tree.get("")) is True
assert should_show(g.ledger.root_tree.get("Expenses")) is False
def test_interval():
assert Interval.get("month") is Interval.MONTH
assert Interval.get("year") is Interval.YEAR
assert Interval.get("YEAR") is Interval.YEAR
assert Interval.get("asdfasdf") is Interval.MONTH
def test_net_worth(app, example_ledger, snapshot):
with app.test_request_context():
app.preprocess_request()
g.conversion = "USD"
data = example_ledger.charts.net_worth(Interval.MONTH)
snapshot(data)
def test_interval_totals(app, small_example_ledger, snapshot):
with app.test_request_context(""):
g.conversion = None
data = small_example_ledger.charts.interval_totals(
Interval.MONTH, "Expenses"
)
snapshot(data)
def test_slugify():
assert slugify("Example Beancount File") == "example-beancount-file"
assert slugify(" Example Beancount File ") == "example-beancount-file"
assert slugify("test") == "test"
assert slugify("烫烫烫") == "烫烫烫"
assert slugify("nonun烫icode 烫烫") == "nonun烫icode-烫烫"
assert slugify("%✓") == ""
assert slugify("söße") == "söße"
assert slugify("ASDF") == "asdf"
assert slugify("ASDF test test") == "asdf-test-test"