コード例 #1
0
ファイル: World_ut.py プロジェクト: kacperros/tkom
 def setUp(self):
     self.world = World()
     self.world.add_currency(Currency('American Dolar', 'USD', 0))
     self.world.add_stock(Stock('CocaCola', 0, 0))
     self.world.set_start_date('2016.05.09')
     self.world.add_currency_rate(0, '2016.05.09', 150.0)
     self.world.add_currency_rate(0, '2016.05.10', 50.0)
     self.world.add_stock_price(0, '2016.05.09', 50.0)
     self.world.add_stock_price(0, '2016.05.10', 55.0)
コード例 #2
0
ファイル: RuleParserTests.py プロジェクト: kacperros/tkom
 def test_getCorrectEvents(self):
     symbol_table = SymbolsTable()
     symbol_table.add_currency('YUA')
     symbol_table.add_currency('USD')
     symbol_table.add_stock('CocaCola')
     symbol_table.add_stock('NukaCola')
     parsed_file = open("rule.txt")
     lexer = Lexer(parsed_file)
     controller = RealityController()
     controller.world.current_day = dC.to_date('2016.05.16')
     controller.world.add_currency(Currency('yuan', 'YUA', 0))
     controller.world.add_currency(Currency('usa dollar', 'USD', 1))
     controller.world.add_stock(Stock('CocaCola', 1, 0))
     controller.world.add_stock(Stock('NukaCola', 1, 1))
     controller.add_event(Event(EventType.CURRENCY, '2016.05.16', 0, 500))
     controller.add_event(Event(EventType.CURRENCY, '2016.05.15', 0, 400))
     controller.add_event(Event(EventType.STOCK, '2016.05.16', 0, 500))
     controller.add_event(Event(EventType.STOCK, '2016.05.15', 0, 400))
     controller.add_event(Event(EventType.STOCK, '2016.05.14', 0, 400))
     controller.add_event(Event(EventType.STOCK, '2016.05.13', 0, 400))
     Parser.RuleParser.parse_from_lexer(lexer, symbol_table, controller)
     rule = controller.rules.get(1)
     print(rule.priority)
コード例 #3
0
    def get_site_data(self):
        """navigate to the url and extract the information"""
        # url = 'https://m.investing.com/currencies/usd-brl'
        try:
            page_soup = get_page_soup_by_url(self.url)

            formatted_currency = self.__get_currency_conversion(page_soup)

            currency_information = self.__get_currency_information_list(
                page_soup)

            return Currency(formatted_currency, currency_information[0],
                            currency_information[1], currency_information[2],
                            currency_information[3])

        except requests.exceptions.HTTPError as http_Error:
            # TODO: GENERATE LOG
            return None
        except AttributeError:
            # TODO: GENERATE LOG
            return None
コード例 #4
0
ファイル: ConfigParser.py プロジェクト: kacperros/tkom
def parse_currencies(currencies, symbol_table):
    counter = 0
    result = []
    for currency in currencies.iter('currency'):
        name_elem = currency.find('name')
        abbrev_elem = currency.find('abbreviation')
        if name_elem is None:
            raise ValueError("Sir, I can not load this file, currency " +
                             str(counter) + "is missing its name")
        elif abbrev_elem is None:
            raise ValueError("Sir, I can not load this file, currency " +
                             str(counter) + "is missing its abbreviation")
        elif name_elem.text == "" or abbrev_elem.text == "":
            raise ValueError("Sir, I can not load this file, currency " +
                             str(counter) + "it can not have empty elements")
        else:
            currency_id = symbol_table.add_currency(abbrev_elem.text)
            result.append(
                Currency(name_elem.text, abbrev_elem.text, currency_id))
        counter += 1
    return result
コード例 #5
0
class CurrencyTests(unittest.TestCase):
    def setUp(self):
        self.currency = Currency('dolar amerykański', 'USD', 1)
        self.currency.add_exchange_rate('2016.05.09', 20.0)
        self.currency.add_exchange_rate('2016.05.12', 25.0)

    def tearDown(self):
        self.currency = None

    def test_getCorrectDate(self):
        self.assertEqual(self.currency.get_exchange_rate('2016.05.09'), 20.0)

    def test_getDateUndefinedDataButInRange(self):
        self.assertEqual(self.currency.get_exchange_rate('2016.05.11'), 20.0)
        self.assertEqual(self.currency.get_exchange_rate('2016.06.12'), 25.0)

    def test_getDateUndefinedNotInRange(self):
        try:
            self.currency.get_exchange_rate('2015.05.11')
            self.assertEqual(1, 2)
        except ValueError:
            self.assertEqual(1, 1)
コード例 #6
0
 def setUp(self):
     self.currency = Currency('dolar amerykański', 'USD', 1)
     self.currency.add_exchange_rate('2016.05.09', 20.0)
     self.currency.add_exchange_rate('2016.05.12', 25.0)