test error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: test error (/thread-40075.html) |
test error - MCL169 - May-29-2023 def get_input_as_int(arg): try: result = int(arg) return result except ValueError: raise ValueError("Argument is not all digits") def file_count(filename, items=None): if items is not None and items not in ['l', 'w', 'c']: raise ValueError("'items=' must be 'l', 'w' or 'c' only") with open(filename, 'r') as file: content = file.read() lines = len(content.splitlines()) words = len(content.split()) chars = len(content) if items == 'l': return lines elif items == 'w': return words elif items == 'c': return chars else: return lines, words, chars def get_lookup_dict(filename): lookup_dict = {} try: with open(filename, 'r') as file: for line in file: columns = line.strip().split(',') if len(columns) == 2: key, value = columns lookup_dict[key] = value else: raise ValueError('Invalid number of columns in line: {}'.format(line)) except IOError: print("Error opening file: {}".format(filename)) return lookup_dict when I run test I get ====================================== 1 error in 27.63s ====================================== (base) user@user-MacBook-Pro ~ % >.... call = CallInfo.from_call(lambda: list(collector.collect()), "collect") opt/anaconda3/lib/python3.9/site-packages/_pytest/main.py:711: in collect for direntry in visit(str(argpath), self._recurse): opt/anaconda3/lib/python3.9/site-packages/_pytest/pathlib.py:667: in visit yield from visit(entry.path, recurse) opt/anaconda3/lib/python3.9/site-packages/_pytest/pathlib.py:667: in visit yield from visit(entry.path, recurse) opt/anaconda3/lib/python3.9/site-packages/_pytest/pathlib.py:652: in visit for entry in os.scandir(path): E PermissionError: [Errno 1] Operation not permitted: '/Users/user/Library/Accounts' =================================== short test summary info =================================== ERROR - PermissionError: [Errno 1] Operation not permitted: '/Users/user/Library/Acc... !!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!! This is my final Homework. there are no errors in pycharm but are when i run test from command here is test: import funclib # funclib.py must be in same directory as this test script def test_get_input_as_int(): x = funclib.get_input_as_int('5') assert x == 5 try: funclib.get_input_as_int('what?') except ValueError: pass else: raise AssertionError("get_input_as_int('what') does not raise a ValueError") def test_file_count(): lines, words, chars = funclib.file_count('FF_tiny.txt') assert lines == 9 assert words == 45 assert chars == 368 lines = funclib.file_count('FF_tiny.txt', items='l') assert lines == 9 words = funclib.file_count('FF_tiny.txt', items='w') assert words == 45 chars = funclib.file_count('FF_tiny.txt', items='c') assert chars == 368 try: funclib.file_count('FF_tiny.txt', items='xxx') except ValueError: pass else: exit('file_count(items=\'xxx\') did NOT raise ValueError') def test_get_lookup_dict(): ret = funclib.get_lookup_dict('pac_man_ghosts.csv') assert ret == {'Shadow': 'Blinky', 'Speedy': 'Pinky', 'Bashful': 'Inky', 'Pokey': 'Clyde'} |