Skip to content

Commit

Permalink
v1.00 Unit-Testing-UIAssets-Module
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronn-M committed Oct 24, 2023
1 parent a012e47 commit 1bd9c8e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 23 deletions.
13 changes: 3 additions & 10 deletions UIAssets.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ def get_currencies():
'United Arab Emirates Dirham': 'AED', 'Vanuatu Vatu': 'VUV', 'Venezuela Bolivar': 'VEB', 'Vietnam Dong': 'VND', 'Yemen Rial': 'YER',
'Zambia Kwacha': 'ZMK', 'Zimbabwe Dollar': 'ZWD'}

return currencies_list


def create_currencylist():

currencies_list = get_currencies()

with open('kv_data/CurrencyList.kv', 'wt') as file:

spacer_i = '\n\n\t'
Expand All @@ -65,8 +58,8 @@ def create_currencylist():
file.write( widget )

file.close()

return
return currencies_list


def convert( convert_from, convert_to, amount ):
Expand All @@ -89,7 +82,7 @@ def convert( convert_from, convert_to, amount ):
new_amount = json.loads( response.text )
new_amount = new_amount[ 'new_amount' ]

return str( new_amount )
return new_amount

else:

Expand Down
Binary file added __pycache__/UIAssets.cpython-310.pyc
Binary file not shown.
28 changes: 15 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

from kivymd.app import MDApp

from UIAssets import convert, create_currencylist, get_currencies


create_currencylist()
from UIAssets import convert, get_currencies

screenmanager = ScreenManager()

Expand All @@ -19,20 +16,20 @@ class CurrencyConverter( MDApp ):
field_name: str
currency_name: str

def build( self ):
def build( self ) -> object:

self.theme_cls.material_style = 'M3'
self.theme_cls.theme_style = 'Dark'
self.theme_cls.material_style = 'M3'

converterui = Builder.load_file( 'kv_data/CurrencyConverterPage.kv' )
currencylist = Builder.load_file( 'kv_data/CurrencyList.kv' )

screenmanager.add_widget( converterui )
screenmanager.add_widget( currencylist )

return screenmanager

def currencylist(self, field_name: str ):
def currencylist(self, field_name: str ) -> None:

screenmanager.current = 'currencylist'
screen = screenmanager.current_screen
Expand All @@ -41,15 +38,15 @@ def currencylist(self, field_name: str ):

Window.release_all_keyboards()

def set_currency( self, currency_name: str, field_name: str ):
def set_currency( self, currency_name: str, field_name: str ) -> None:

screenmanager.current = 'converterui'
screen = screenmanager.current_screen

if field_name == 'convertto': screen.ids.convertto.text = currency_name
if field_name == 'convertfrom': screen.ids.convertfrom.text = currency_name

def converterui( self, *args: str ):
def converterui( self, *args: str ) -> None:

screenmanager.current = 'converterui'
screen = screenmanager.current_screen
Expand All @@ -62,12 +59,17 @@ def converterui( self, *args: str ):

currencies_list = get_currencies()

converted_amount = convert( currencies_list[ convertfrom ],
converted_amount = str( convert( currencies_list[ convertfrom ],
currencies_list[ convertto ],
amount )
amount ) )

screen.ids.amount.text = ''
screen.ids.result.text = f'{ converted_amount } { currencies_list[ convertto ] }'

if converted_amount != 'Connection Error!' and converted_amount != 'Database Error!':

screen.ids.result.text = f'{ converted_amount } { currencies_list[ convertto ] }'

else: screen.ids.result.text = converted_amount

else:

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kivy
kivymd
Empty file added tests/__init__.py
Empty file.
46 changes: 46 additions & 0 deletions tests/test_uiassets_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import sys

wd = '/home/sr-ronn-m/Documents/Python Projects/CurrencyConverterApp/'

sys.path.insert(0, wd)

import UIAssets

def test_get_currencies_default() -> None:

result = UIAssets.get_currencies()

assert type(result) is dict

def test_convert_default() -> None:

req_format_0 = 'USD'
req_format_1 = 'AUD'
req_format_2 = 1000

result = UIAssets.convert(req_format_0, req_format_1, req_format_2)

assert type(result) is float or result == 'Connection Error!'

def test_convert_default_str() -> None:

req_format_0 = 'USD'
req_format_1 = 'AUD'
req_format_2 = '1000'

result = UIAssets.convert(req_format_0, req_format_1, req_format_2)

assert type(result) is float or result == 'Connection Error!'

def test_convert_unknown_str() -> None:

req_format_0 = 'USD'
req_format_1 = 'AUD'
req_format_2 = 'ABC'

result = UIAssets.convert(req_format_0, req_format_1, req_format_2)

print('true')

assert result == 'Database Error!' or result == 'Connection Error!'

0 comments on commit 1bd9c8e

Please sign in to comment.