def test_execute_query(example_ledger): query_shell = QueryShell(example_ledger) assert query_shell.execute_query("help exit") == ( QueryShell.noop.__doc__ + "\n", None, None, ) assert query_shell.execute_query("help")[1:] == (None, None) assert query_shell.execute_query("balances")[1:] == query.run_query( query_shell.entries, query_shell.options_map, "balances")
def test_execute_query(example_ledger): query_shell = QueryShell(example_ledger) assert query_shell.execute_query('help exit') == \ (QueryShell.noop.__doc__ + '\n', None, None) assert query_shell.execute_query('help')[1:] == \ (None, None) assert query_shell.execute_query('balances', add_to_history=True)[1:] == \ query.run_query(query_shell.entries, query_shell.options_map, 'balances') assert query_shell.get_history(1) == ['balances']
def __init__(self, path): #: The path to the main Beancount file. self.beancount_file_path = path self._is_encrypted = is_encrypted_file(path) self._filters = { 'account': AccountFilter(), 'from': FromFilter(), 'payee': PayeeFilter(), 'tag': TagFilter(), 'time': TimeFilter(), } #: An :class:`AttributesModule` instance. self.attributes = AttributesModule(self) #: A :class:`.BudgetModule` instance. self.budgets = BudgetModule(self) #: A :class:`.ChartModule` instance. self.charts = ChartModule(self) #: A :class:`.ExtensionModule` instance. self.extensions = ExtensionModule(self) #: A :class:`.FileModule` instance. self.file = FileModule(self) #: A :class:`.IngestModule` instance. self.ingest = IngestModule(self) #: A :class:`.FavaMisc` instance. self.misc = FavaMisc(self) #: A :class:`.QueryShell` instance. self.query_shell = QueryShell(self) self._watcher = Watcher() #: List of all (unfiltered) entries. self.all_entries = None #: Dict of list of all (unfiltered) entries by type. self.all_entries_by_type = None #: A list of all errors reported by Beancount. self.errors = None #: A Beancount options map. self.options = None #: A Namedtuple containing the names of the five base accounts. self.account_types = None #: A dict containing information about the accounts. self.accounts = _AccountDict() #: A dict with all of Fava's option values. self.fava_options = None self.load_file()
def __init__(self, path: str) -> None: #: The path to the main Beancount file. self.beancount_file_path = path self._is_encrypted = is_encrypted_file(path) #: An :class:`AttributesModule` instance. self.attributes = AttributesModule(self) #: A :class:`.BudgetModule` instance. self.budgets = BudgetModule(self) #: A :class:`.ChartModule` instance. self.charts = ChartModule(self) #: A :class:`.ExtensionModule` instance. self.extensions = ExtensionModule(self) #: A :class:`.FileModule` instance. self.file = FileModule(self) #: A :class:`.IngestModule` instance. self.ingest = IngestModule(self) #: A :class:`.FavaMisc` instance. self.misc = FavaMisc(self) #: A :class:`.DecimalFormatModule` instance. self.format_decimal = DecimalFormatModule(self) #: A :class:`.QueryShell` instance. self.query_shell = QueryShell(self) self._watcher = Watcher() #: List of all (unfiltered) entries. self.all_entries = [] #: Dict of list of all (unfiltered) entries by type. self.all_entries_by_type = group_entries_by_type([]) #: A list of all errors reported by Beancount. self.errors: list[BeancountError] = [] #: A Beancount options map. self.options: BeancountOptions = OPTIONS_DEFAULTS #: A dict containing information about the accounts. self.accounts = AccountDict() #: A dict with commodity names (from the 'name' metadata) self.commodity_names: dict[str, str] = {} #: A dict with all of Fava's option values. self.fava_options: FavaOptions = FavaOptions() self._date_first: datetime.date | None = None self._date_last: datetime.date | None = None self.load_file()
def __init__(self, path: str) -> None: #: The path to the main Beancount file. self.beancount_file_path = path self._is_encrypted = is_encrypted_file(path) #: An :class:`AttributesModule` instance. self.attributes = AttributesModule(self) #: A :class:`.BudgetModule` instance. self.budgets = BudgetModule(self) #: A :class:`.ChartModule` instance. self.charts = ChartModule(self) #: A :class:`.ExtensionModule` instance. self.extensions = ExtensionModule(self) #: A :class:`.FileModule` instance. self.file = FileModule(self) #: A :class:`.IngestModule` instance. self.ingest = IngestModule(self) #: A :class:`.FavaMisc` instance. self.misc = FavaMisc(self) #: A :class:`.DecimalFormatModule` instance. self.format_decimal = DecimalFormatModule(self) #: A :class:`.QueryShell` instance. self.query_shell = QueryShell(self) self._watcher = Watcher() #: List of all (unfiltered) entries. self.all_entries = [] #: Dict of list of all (unfiltered) entries by type. self.all_entries_by_type: Dict[Type[Directive], Entries] = {} #: A list of all errors reported by Beancount. self.errors: List[BeancountError] = [] #: A Beancount options map. self.options: Dict[str, Any] = {} #: A dict containing information about the accounts. self.accounts = AccountDict() #: A dict containing information about the commodities self.commodities: Dict[str, Commodity] = {} #: A dict with all of Fava's option values. self.fava_options: FavaOptions = {} self.load_file()
def test_query_to_file(example_ledger): query_shell = QueryShell(example_ledger) name, data = query_shell.query_to_file('balances', 'csv') assert name == 'query_result' csv = os.path.join(os.path.dirname(__file__), 'data/example-balances.csv') with open(csv, 'rb') as file: assert data.getvalue() == file.read() with pytest.raises(FavaAPIException): query_shell.query_to_file('select sdf', 'csv') with pytest.raises(FavaAPIException): query_shell.query_to_file('run testsetest', 'csv')
def test_query_to_file(example_ledger): query_shell = QueryShell(example_ledger) name, data = query_shell.query_to_file("balances", "csv") assert name == "query_result" csv = data_file("example-balances.csv") with open(csv, "rb") as file: assert data.getvalue() == file.read() with pytest.raises(FavaAPIException): query_shell.query_to_file("select sdf", "csv") with pytest.raises(FavaAPIException): query_shell.query_to_file("run testsetest", "csv")
def test_execute_query(example_ledger): query_shell = QueryShell(example_ledger) assert query_shell.execute_query('help exit') == \ (QueryShell.noop.__doc__ + '\n', None, None) assert query_shell.execute_query('help')[1:] == \ (None, None) assert query_shell.execute_query('balances', add_to_history=True)[1:] == \ query.run_query(query_shell.entries, query_shell.options_map, 'balances') assert query_shell.get_history(1) == ['balances']
def test_query_to_file(example_ledger): query_shell = QueryShell(example_ledger) name, data = query_shell.query_to_file('balances', 'csv') assert name == 'query_result' csv = data_file('example-balances.csv') with open(csv, 'rb') as file: assert data.getvalue() == file.read() with pytest.raises(FavaAPIException): query_shell.query_to_file('select sdf', 'csv') with pytest.raises(FavaAPIException): query_shell.query_to_file('run testsetest', 'csv')
def __init__(self, path): s3_file_backend = S3FileBackend(self, path) #: The path to the main Beancount file. self.beancount_file_path = path if s3_file_backend.active: self.beancount_file_path = s3_file_backend.beancount_file_path self._is_encrypted = is_encrypted_file(path) self._filters = {} #: An :class:`AttributesModule` instance. self.attributes = AttributesModule(self) #: A :class:`.BudgetModule` instance. self.budgets = BudgetModule(self) #: A :class:`.ChartModule` instance. self.charts = ChartModule(self) #: A :class:`.ExtensionModule` instance. self.extensions = ExtensionModule(self) #: A :class:`.FileModule` instance. self.file = FileModule(self) if s3_file_backend.active: self.file = s3_file_backend #: A :class:`.IngestModule` instance. self.ingest = IngestModule(self) #: A :class:`.FavaMisc` instance. self.misc = FavaMisc(self) #: A :class:`.DecimalFormatModule` instance. self.format_decimal = DecimalFormatModule(self) #: A :class:`.QueryShell` instance. self.query_shell = QueryShell(self) self._watcher = Watcher() #: List of all (unfiltered) entries. self.all_entries = None #: Dict of list of all (unfiltered) entries by type. self.all_entries_by_type = None #: A list of all errors reported by Beancount. self.errors = None #: A Beancount options map. self.options = None #: A Namedtuple containing the names of the five base accounts. self.account_types = None #: A dict containing information about the accounts. self.accounts = _AccountDict() #: A dict with all of Fava's option values. self.fava_options = None self.load_file()