I have this code for add_setting()
def add_setting(settings_dic, req_tuple):
#unpacking a dic and defining new lowered k:v members
settings_dic = {k.lower(): v.lower() for k, v in settings_dic.items()}
#unpacking a tuple
k, v = req_tuple
print(f'k, v in req_tuple= {k}, {v}')
req_tuple = (k.lower(), v.lower())
req_key, req_value = req_tuple
print(f'k, v in req_tuple= {req_key}, {req_value}')
if req_key in settings_dic.keys():
return f"Setting '{req_key}' already exists! Cannot add a new setting with this name."
else:
settings_dic[req_key] = req_value
print(f'\ninside_func:\nsettings_dic after added things={settings_dic}')
return f"Setting '{req_key}' added with value '{req_value}' successfully!"
I also have written a test:
def test_this_file():
print('\n======\nTests:\n')
print("\n add_setting() output 1:\n", add_setting(test_settings , ('volume', 'high')))
print("\n add_setting() output 2:\n", add_setting({'tHeme': 'light'}, ('Volume', 'high')))
#print(f'\noutside_func:\nsettings_dic after added things={settings_dic}')
return
which outputs this:
======
Tests:
k, v in req_tuple= volume, high
k, v in req_tuple= volume, high
add_setting() output 1:
Setting 'volume' already exists! Cannot add a new setting with this name.
k, v in req_tuple= Volume, high
k, v in req_tuple= volume, high
inside_func:
settings_dic after added things={'theme': 'light', 'volume': 'high'}
add_setting() output 2:
Setting 'volume' added with value 'high' successfully!
Now my questions:
Q0. Should have I opened a new topic or what?
Q1. I get the following message
> Failed: 4. add_setting should convert the key to lowercase.
However my tests output tells me I have already done it. (Or I see it like this)
Q2. in the same way I get the message below
> Failed: 5. add_setting should convert the value to lowercase.
Even 7 and 8 (to me) seems passed when I see my test results:
Failed 7. add_setting({'theme': 'light'}, ('volume', 'high')) should add a new key-value pair and return the success message Setting 'volume' added with value 'high' successfully!.
Failed: 8. add_setting should correctly add the given key-value pair to the dictionary.
I wanna take the most of these precious projects. So it would be nice to know if:
Q4) Does the tester in website works in the way I am explaining? It gets my file. the tester is another file running as main function which reads my py-file, finds the desired defined function and calls it with plenty of its own test cases and checks if desired outputs are there.
Q5 ) Can we see inside those test files (if there is any open) to get better understanding of writing the test or even knowing what exactly are we supposed to provide?
Q6) when I come across this part of my own code:
#unpacking a tuple
k, v = req_tuple
print(f'k, v in req_tuple= {k}, {v}')
req_tuple = (k.lower(), v.lower())
req_key, req_value = req_tuple
print(f'k, v in req_tuple= {req_key}, {req_value}')
It seems to me that I changed a tuple! Am I wrong? if not, wasn’t a tuple meant to be unchangeable? Please let me know where my problem is.
I know this was not asked in the lab project. But the answer is important to me.