def setUp(self): self.converter = CurrencyConverter()
def setUp(self): self.converter = CurrencyConverter() self.rates = {"USD": 0.87, "EUR": 1, "CZK": 0.04}
def test_construct_6(self): """Rates file is missing and rates_rad_mode is set to 'api'.""" try: CurrencyConverter(app_id, 'api', symbols_filepath) except Exception, e: self.fail(e)
def setUp(self): self.converter = CurrencyConverter() # rates relative to EUR, actual on 11.1.2019 self.USD_rate = 0.87 # 1USD = 0.86764 EUR self.EUR_rate = 1 self.CZK_rate = 0.04
def test_construct_4(self): """If invalid rates read mode is entered, raise an exception.""" with self.assertRaises(ValueError) as context: CurrencyConverter(app_id, 'fXXXile', symbols_filepath, rates_filepath) self.assertTrue(4 in context.exception)
def test_construct_5(self): """Rates file is set and exists.""" try: CurrencyConverter(app_id, 'file', symbols_filepath, rates_filepath) except Exception, e: self.fail(e)
def test_construct_3(self): """If currency symbols file does not exist, raise an exception.""" with self.assertRaises(IOError) as context: CurrencyConverter(app_id, 'file', 'XYZ.XXX', rates_filepath) self.assertTrue(3 in context.exception)
def test_construct_2(self): """If rates file is missing, but rates_read_mode is not set to 'api', raise an exception.""" with self.assertRaises(ValueError) as context: CurrencyConverter(app_id, 'file', symbols_filepath) self.assertTrue(2 in context.exception)
def test_construct_1(self): """If rates file is set, but does not exist, raise an exception.""" with self.assertRaises(IOError) as context: CurrencyConverter(app_id, 'file', symbols_filepath, 'XYZ.XXX') self.assertTrue(1 in context.exception)
def setUp(self): """Create an object which will be used for testing convert() method.""" self.c_converter = CurrencyConverter(app_id, 'file_no_update', symbols_filepath, rates_filepath)
from src.CurrencyConverter import CurrencyConverter # Get directory of the file. current_dir = os.path.dirname(os.path.realpath(__file__)) # Get API key from config file. with open(os.path.abspath(current_dir+'/config.txt')) as config_file: app_id = config_file.read().strip() # Set filepaths rates_filepath = os.path.abspath(current_dir+'/rates_files/latest.json') symbols_filepath = os.path.abspath(current_dir+'/cur_symbols/currency_symbols.txt') # Create the main object. converter = CurrencyConverter(app_id, 'api', symbols_filepath, rates_filepath) # If the file was imported (as module). def convert_money(amount, input_cur, output_cur=None): return converter.convert(amount, input_cur, output_cur) # If the file was run directly (as script). if __name__ == '__main__': # Module required for command line parsing. import argparse # Save terminal encoding terminal_encoding = sys.stdin.encoding # Parse the incoming arguments