Use pathlib in test_user_car
This commit is contained in:
parent
4cc4b2ead4
commit
8441c6acfb
@ -37,12 +37,12 @@
|
||||
from random import shuffle ## allowing us to randomize selection of cars.
|
||||
import glob ## allowing us to search the file system for .choochoo files.
|
||||
import sys ## so we can read command line arguments.
|
||||
import getpass ## so we can get the user's username
|
||||
import curses
|
||||
from signal import signal, SIGINT
|
||||
import time ## allowing the loop steps of train animation to be slowed
|
||||
import string ## for input validation
|
||||
from inspect import cleandoc
|
||||
from pathlib import Path
|
||||
|
||||
traincarFN = ".choochoo"
|
||||
max_x = 35 ## max length of train car.
|
||||
@ -122,16 +122,15 @@ def print_help():
|
||||
|
||||
|
||||
def test_user_car():
|
||||
username = getpass.getuser()
|
||||
fname = "/home/" + username + "/" + traincarFN
|
||||
fname = Path.home() / traincarFN
|
||||
try:
|
||||
myfile = open(fname, 'r')
|
||||
except:
|
||||
print("ERROR: Couldn't open " + fname)
|
||||
print("Either it doesn't exist, or is not readble by the tilde.train script.")
|
||||
sys.exit(1)
|
||||
choochoo_string = fname.read_text("utf-8")
|
||||
except OSError as err:
|
||||
raise OSError(
|
||||
f"Couldn't open {fname}\n"
|
||||
"Either it doesn't exist, or is not readble by the tilde.train script."
|
||||
) from err
|
||||
|
||||
choochoo_string = myfile.read()
|
||||
choochoo_list = choochoo_string.split("\n")
|
||||
|
||||
car = "\n".join(choochoo_list)
|
||||
@ -177,17 +176,14 @@ def test_user_car():
|
||||
if train_height > max_y+1:
|
||||
print("FAIL. Your train car is too tall.")
|
||||
print("It should be no taller than " + str(max_y) + " lines in height.")
|
||||
myfile.close()
|
||||
sys.exit(1)
|
||||
|
||||
if train_length > max_x:
|
||||
print("FAIL. Your train car is too long.")
|
||||
print("It should be no longer than " + str(max_x) + " characters in length.")
|
||||
myfile.close()
|
||||
sys.exit(1)
|
||||
|
||||
print("PASS. Your train car will work on the tilde.town tracks! :)")
|
||||
myfile.close()
|
||||
sys.exit()
|
||||
|
||||
def link_car(car):
|
||||
|
Loading…
x
Reference in New Issue
Block a user