Skip to content

Commit

Permalink
feat: add account repr for pythong binding
Browse files Browse the repository at this point in the history
  • Loading branch information
Kilerd committed Oct 10, 2023
1 parent 8fe8b00 commit 5834a4b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 7 additions & 0 deletions bindings/python/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ impl Account {
pub fn name(&self) -> String {
self.0.content.clone()

Check warning on line 14 in bindings/python/src/ast.rs

View check run for this annotation

Codecov / codecov/patch

bindings/python/src/ast.rs#L13-L14

Added lines #L13 - L14 were not covered by tests
}

pub fn __str__(&self) -> &str {
&self.0.content

Check warning on line 18 in bindings/python/src/ast.rs

View check run for this annotation

Codecov / codecov/patch

bindings/python/src/ast.rs#L17-L18

Added lines #L17 - L18 were not covered by tests
}
pub fn __repr__(&self) -> String {
format!("<Account: {}>", &self.0.content)

Check warning on line 21 in bindings/python/src/ast.rs

View check run for this annotation

Codecov / codecov/patch

bindings/python/src/ast.rs#L20-L21

Added lines #L20 - L21 were not covered by tests
}
}
16 changes: 13 additions & 3 deletions bindings/python/test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@

from zhang import Ledger
from pprint import pprint
from terminaltables import AsciiTable

print("loading examples/example.zhang")
ledger = Ledger("../../examples", "example.zhang")
print("printing options")
pprint(ledger.options)
print("printing accounts info")
pprint(ledger.accounts)
options = [
["option key", "option value"],
]
options.extend([[key, ledger.options[key]] for key in ledger.options])
print(AsciiTable(options).table)

accounts = [
["Account name", "type", "status", "alias"]
]
accounts.extend([[account.name, account.type, account.status, account.alias] for account in ledger.accounts.values()])

print(AsciiTable(accounts).table)

0 comments on commit 5834a4b

Please sign in to comment.