Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
test error
#1
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'}
buran write May-30-2023, 08:08 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Please, be advised that if you keep ignoring moderator requests to follow forum rules and use proper BBCode tags, any threads you post in the future will be locked
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020