MCPcopy Index your code
hub / github.com/python/cpython / test

Function test

Lib/tkinter/filedialog.py:448–488  ·  view source on GitHub ↗

Simple test program.

()

Source from the content-addressed store, hash-verified

446# test stuff
447
448def test():
449 """Simple test program."""
450 root = Tk()
451 root.withdraw()
452 fd = LoadFileDialog(root)
453 loadfile = fd.go(key="test")
454 fd = SaveFileDialog(root)
455 savefile = fd.go(key="test")
456 print(loadfile, savefile)
457
458 # Since the file name may contain non-ASCII characters, we need
459 # to find an encoding that likely supports the file name, and
460 # displays correctly on the terminal.
461
462 # Start off with UTF-8
463 enc = "utf-8"
464
465 # See whether CODESET is defined
466 try:
467 import locale
468 locale.setlocale(locale.LC_ALL,'')
469 enc = locale.nl_langinfo(locale.CODESET)
470 except (ImportError, AttributeError):
471 pass
472
473 # dialog for opening files
474
475 openfilename=askopenfilename(filetypes=[("all files", "*")])
476 try:
477 fp=open(openfilename,"r")
478 fp.close()
479 except BaseException as exc:
480 print("Could not open File: ")
481 print(exc)
482
483 print("open", openfilename.encode(enc))
484
485 # dialog for saving files
486
487 saveasfilename=asksaveasfilename()
488 print("saveas", saveasfilename.encode(enc))
489
490
491if __name__ == '__main__':

Callers 1

filedialog.pyFile · 0.70

Calls 9

TkClass · 0.90
LoadFileDialogClass · 0.85
SaveFileDialogClass · 0.85
askopenfilenameFunction · 0.85
asksaveasfilenameFunction · 0.85
openFunction · 0.50
goMethod · 0.45
closeMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…