def test_partially_specified_parser(self): keys = {PARSER_PREFIX + "_1": 'bar'} config = ConfigProvider(keys) with self.assertRaises(Exception) as context: config.get_parsers() self.assertTrue("Partially specified parser" in str(context.exception))
def test_get_parsers_none(self): keys = {'foo': 'bar'} config = ConfigProvider(keys) with self.assertRaises(Exception) as context: config.get_parsers() self.assertTrue( "No parsers specified in config" in str(context.exception))
def test_unknown_parser(self): keys = { PARSER_PREFIX + "_1": 'bar', ACCOUNT_PREFIX + "_1": 'bar', ACCOUNT_MATCHER_PREFIX + "_1": 'bar' } config = ConfigProvider(keys) with self.assertRaises(Exception) as context: config.get_parsers() self.assertTrue("Unknown parser requested" in str(context.exception))
def lambda_handler(event, context): print("This is actual Mail To Ynab") config = get_config_from_env() dryrun = False config_provider = ConfigProvider(config) mty = MailToYnab(config_provider, dryrun) result = mty.run() return {'message': result}
def __init__(self, path, parent=None): super().__init__(parent) self.orm = ORM(path) fm = FileManager(ConfigProvider.getLibraryPath()) tracks = fm.walk() self.orm.addTracks(tracks) tracks = self.orm.getTracks() self.rows = tracks self.headers = Track.attributes()
def test_get_parsers_two(self): keys = { PARSER_PREFIX + "_1": 'DiscoveryBankZaParser', ACCOUNT_PREFIX + "_1": 'account_disc', ACCOUNT_MATCHER_PREFIX + "_1": '1234', PARSER_PREFIX + "_2": 'InvestecZaParser', ACCOUNT_PREFIX + "_2": 'account_inv', ACCOUNT_MATCHER_PREFIX + "_2": '5678' } config = ConfigProvider(keys) parsers = config.get_parsers() self.assertEqual(2, len(parsers), "Expected two parsers") p1 = parsers[0] self.assertTrue(isinstance(p1, DiscoveryBankZaParser)) self.assertEqual(p1.account, "account_disc") self.assertTrue(p1.account_matcher.matches("1234")) p2 = parsers[1] self.assertTrue(isinstance(p2, InvestecZaParser)) self.assertEqual(p2.account, "account_inv") self.assertTrue(p2.account_matcher.matches("5678"))
def local_handler(): home = os.getenv("HOME") config_path = home + '/.mail_to_ynab' config = get_config_from_file(config_path) if "dump-config" in sys.argv: structure = {"Variables": config} print(json.dumps(structure)) sys.exit() dryrun = "dryrun" in sys.argv config_provider = ConfigProvider(config) mty = MailToYnab(config_provider, dryrun) print(f"sys.argv: {sys.argv}") if "test-ynab" in sys.argv: mty.test_ynab() else: mty.run()
def initMainWidget(self): # table settings go tableHeaderView = QHeaderView(0x1) tableHeaderView.setCascadingSectionResizes(True) tableView = QTableView(tableHeaderView) tableView.horizontalHeader().setStretchLastSection(True) model = TableModel(ConfigProvider.getDbPath()) tableView.setModel(model) button = QPushButton('click') button.clicked.connect(self.onButtonClicked) topLayout = QVBoxLayout() topLayout.addWidget(button) topLayout.addWidget(tableView) mainWidget = QWidget() mainWidget.setLayout(topLayout) return mainWidget
from flask import Flask, render_template from config_provider import ConfigProvider import os import function app = Flask(__name__) config = ConfigProvider() # Получение содержимого страницы def get_page(name): file = os.path.join(config.pages_folder, name + '.md') # Если страница существует if function.check_found_file(file): page = function.markdown_to_html(file) else: page = config.not_found_text return page @app.route('/') def hello(): return render_template('page.html', title=config.main_title, side=get_page(config.side_bar), content=get_page(config.start_page)) @app.route('/<name>')
import os import sys import shutil from jinja2 import Environment, FileSystemLoader import functions_working_with_fs from config_provider import ConfigProvider import markdown from myextension import MyExtension CONFIG = ConfigProvider() def markdown_to_html(filepath): with open(filepath, 'r', encoding='utf-8') as f: text_file = f.read() html = markdown.markdown( text_file, extensions=['markdown.extensions.codehilite', MyExtension()]) return html def get_arcticles_md(filepath): if functions_working_with_fs.check_file_to_read(filepath): return functions_working_with_fs.read_json_file(filepath) def generate_path_to_html(file_md): root = os.path.splitext(file_md)[0] return os.path.join(CONFIG.path_to_html, root) + CONFIG.ext_html
import data_organizer as do # 分析データ別の設定 confFilePath:str="./config/option.ini" confSection:str="MANSION" args: list[str] = sys.argv if 2 <= len(args): sectionValue:str=args[1] if sectionValue=="TOCHI": confSection=sectionValue conf:ConfigProvider=ConfigProvider(confFilePath,"utf-8") indexColumn=conf.get(confSection,"indexColumn") targetColumn=conf.get(confSection,"targetColumn") unusedColumns=json.loads(conf.get(confSection,"unusedColumns")) modelFilePath=conf.get(confSection,"modelFilePathGdrive") if not os.path.exists(modelFilePath): modelFilePath=conf.get(confSection,"modelFilePathLocal") resultFileName = conf.get(confSection,"resultFileName") resultFolderPath=conf.get(confSection,"resultFolderPathGdrive") resultFolderPathLocal=conf.get(confSection,"resultFolderPathLocal") pickleFileName=conf.get(confSection,"pickleFileName") resultFilePath=resultFolderPathLocal+resultFileName pickleFilePath=resultFolderPathLocal+pickleFileName if os.path.exists(resultFolderPath): resultFilePath=resultFolderPath + resultFileName
def __init__(self): self.config = ConfigProvider().parse()
def test(self): config_data = ConfigProvider().parse() self.assertTrue(config_data['size'] is not '') self.assertTrue(config_data['api_key'] is not '') self.assertTrue(config_data['snapshot'] is not '')