def test_get_default_currency(self): self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY] = 'BRL' with patch.object(sys, 'argv', 'program --get-default-currency'.split()): rates.main(self.wf) self.assertEqual(len(self.wf._items), 1) self.assertEqual(self.wf._items[0].title, 'Your default currency is: BRL')
def test_get_default_divisor(self): self.wf.settings.clear() with patch.object(sys, 'argv', 'program --get-default-divisor'.split()): rates.main(self.wf) self.assertEqual(self.wf._items[0].title, "No number divisor set, using the default '.'")
def test_get_default_divisor_setted(self): self.wf.settings[rates.SETTINGS_DEFAULT_NUMBER_DIVISOR] = ',' with patch.object(sys, 'argv', 'program --get-default-divisor'.split()): rates.main(self.wf) self.assertEqual(self.wf._items[0].title, "The number divisor is: ','")
def test_convert_from_other_to_default_multi_query(self): with patch.object(sys, 'argv', ['program', '100 BRL CLP; GBP 100; 100 GBP CAD']): rates.main(self.wf) self.assertEqual(len(self.wf._items), 3) self.assertNotEqual(self.wf._items[0].subtitle.find('(Brazilian real) -> (Chilean peso) with rate'), -1) self.assertNotEqual(self.wf._items[1].subtitle.find('(British pound [B]) -> (Brazilian real) with rate'), -1) self.assertNotEqual(self.wf._items[2].subtitle.find('(British pound [B]) -> (Canadian dollar) with rate'), -1)
def test_convert_from_default_to_other_without_values(self): self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY] = 'USD' with patch.object(sys, 'argv', ['program', 'BRL']): rates.main(self.wf) self.assertTrue(len(self.wf._items), 1) self.assertNotEqual(self.wf._items[0].subtitle.find('USD (United States dollar) -> BRL (Brazilian real)'), -1)
def test_convert_from_detault_to_other_without_values_multi_query(self): self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY] = 'USD' with patch.object(sys, 'argv', ['program', '100 BRL CLP; GBP; 100 GBP CAD']): rates.main(self.wf) self.assertEqual(len(self.wf._items), 3) self.assertNotEqual(self.wf._items[0].subtitle.find('(Brazilian real) -> (Chilean peso) with rate'), -1) self.assertNotEqual(self.wf._items[1].subtitle.find('(United States dollar) -> (British pound [B]) with rate'), -1) self.assertNotEqual(self.wf._items[2].subtitle.find('(British pound [B]) -> (Canadian dollar) with rate'), -1)
def test_clear_caches(self): self.wf.cache_data('test_cache', 'testing cache') self.wf.store_data('test_store', 'testing store') with patch.object(sys, 'argv', 'program --clear'.split()): rates.main(self.wf) self.assertEqual(len(self.wf._items), 1) self.assertEqual(self.wf._items[0].title, 'Caches cleared!') self.assertIsNone(self.wf.stored_data('test_store')) self.assertIsNone(self.wf.cached_data('test_cache'))
def test_convert_high_rates(self): # Test the problem reported in #14, converting from idr to usd # Yahoo will return as rate 0.0001, because it's the minimum # but the rate is something around 0.000007... with patch.object(sys, 'argv', ['program', '1 idr usd']): rates.main(self.wf) # must have only 1 item self.assertEqual(len(self.wf._items), 1) # must not be rate 0.0001 for query self.assertEqual(self.wf._items[0].subtitle.find('(Indonesian rupiah) -> (United States dollar) with rate 0.0001 for query'), -1) # must be a conversion message self.assertNotEqual(self.wf._items[0].subtitle.find('(Indonesian rupiah) -> (United States dollar) with rate'), -1)
def test_convert_eur(self): # This test is because of a bug with displaying EUR symbol with patch.object(sys, 'argv', 'program 1 USD EUR'.split()): rates.main(self.wf) self.assertEqual(len(self.wf._items), 1) self.assertNotEqual(self.wf._items[0].subtitle.find('USD (United States dollar) -> EUR (Euro) with rate'), -1)
def test_full_convert(self): with patch.object(sys, 'argv', ['program', '100', 'BRL', 'CLP']): rates.main(self.wf) self.assertEqual(len(self.wf._items), 1) self.assertNotEqual(self.wf._items[0].subtitle.find('BRL (Brazilian real) -> CLP (Chilean peso) with rate'), -1)
def test_invalid_currency_number_to_convert(self): with patch.object(sys, 'argv', ['program', 'zupa BRL USD']): ret = rates.main(self.wf) self.assertTrue(ret, 100)
def test_set_default_divisor_dot(self): with patch.object(sys, 'argv', 'program --set-default-divisor .'.split()): rates.main(self.wf) self.assertEqual(self.wf._items[0].title, "Default divisor updated to: '.'")
def test_set_wrong_default_divisor(self): with patch.object(sys, 'argv', 'program --set-default-divisor ;'.split()): rates.main(self.wf) self.assertEqual(self.wf._items[0].title, "Wrong divisor, please specify '.' or ','.")
def test_set_invalid_currency(self): with patch.object(sys, 'argv', 'program --set-default-currency zupa'.split()): rates.main(self.wf) self.assertEqual(len(self.wf._items), 1) self.assertEqual(self.wf._items[0].title, 'You entered a invalid currency...')
def test_convert_from_other_to_default(self): with patch.object(sys, 'argv', ['program', 'CLP', '100']): rates.main(self.wf) self.assertEqual(len(self.wf._items), 1) self.assertNotEqual(self.wf._items[0].subtitle.find('CLP (Chilean peso) -> BRL (Brazilian real) with rate'), -1)
def test_set_default_currency(self): with patch.object(sys, 'argv', ['program', '--set-default-currency', 'BRL']): rates.main(self.wf) self.assertEqual(self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY], 'BRL')
def test_default_currency(self): with patch.object(sys, 'argv', ['program', '--get-default-currency']): rates.main(self.wf) self.assertEqual(len(self.wf._items), 1) self.assertEqual(self.wf._items[0].title, 'No default currency.')
def test_invalid_currency_number_to_convert_using_default(self): with patch.object(sys, 'argv', 'program zupa BRL'.split()): ret = rates.main(self.wf) self.assertTrue(ret, 100)
def test_convert_case_insensitive(self): with patch.object(sys, 'argv', 'program 1 brl clp'.split()): rates.main(self.wf) self.assertEqual(len(self.wf._items), 1) self.assertNotEqual(self.wf._items[0].subtitle.find('BRL (Brazilian real) -> CLP (Chilean peso) with rate'), -1)
def test_invalid_argument(self): with patch.object(sys, 'argv', 'program zupa'.split()): ret = rates.main(self.wf) # 100 means auto complete self.assertEqual(ret, 100)