Skip to content

Commit 5472ff4

Browse files
committed
fix: fix test error
1 parent 812d576 commit 5472ff4

5 files changed

Lines changed: 38 additions & 160 deletions

File tree

README-zh-cn.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107

108108
```python
109109
>>> import string
110-
110+
>>>
111111
>>> # not locale-dependent
112112
>>> string.ascii_letters
113113
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -958,7 +958,7 @@ pickle A
958958
>>> import shelve
959959
>>>
960960
>>> # Open a shelf file (creates if not exists)
961-
>>> with shelve.open('geenrated/mydata.db') as db:
961+
>>> with shelve.open('generated/mydata.db') as db:
962962
... # Basic operations: set, get, delete, check existence
963963
... db['name'] = 'Alice'
964964
... db['numbers'] = [1, 2, 3]
@@ -977,12 +977,12 @@ pickle A
977977
... # Sync to ensure data is written to disk
978978
... db.sync()
979979
...
980-
Alice
980+
'Alice'
981981
True
982982
['name', 'numbers']
983983
>>>
984984
>>> # Re-open with writeback=True for direct modification
985-
>>> db = shelve.open('mydata.db', writeback = True)
985+
>>> db = shelve.open('generated/mydata.db', writeback = True)
986986
>>> db['numbers'].append(5) # Direct modify (auto-persisted on close)
987987
>>> db['numbers']
988988
[1, 2, 3, 4, 5]
@@ -1400,31 +1400,31 @@ _wave_params(nchannels=2, sampwidth=2, framerate=44100, nframes=442368, comptype
14001400
>>>
14011401
>>> zh_trans = gettext.translation(
14021402
... DOMAIN,
1403-
... localedir=LOCALE_DIR,
1404-
... languages=['zh'],
1405-
... fallback=True # 找不到 .mo 时不报错
1403+
... localedir = LOCALE_DIR,
1404+
... languages = ['zh'],
1405+
... fallback = True
14061406
... )
14071407
>>>
14081408
>>> en_trans = gettext.translation(
14091409
... DOMAIN,
1410-
... localedir=LOCALE_DIR,
1411-
... languages=['en'],
1412-
... fallback=True
1410+
... localedir = LOCALE_DIR,
1411+
... languages = ['en'],
1412+
... fallback = True
14131413
... )
14141414
>>>
14151415
>>> _zh = zh_trans.gettext # Get the specific gettext function from the instance
14161416
>>> _zh('hello_world')
1417-
你好,世界!
1417+
'你好,世界!'
14181418
>>>
14191419
>>> # Install the Chinese translation globally
14201420
>>> # This sets the global _() function for all modules to use zh_trans.
14211421
>>> zh_trans.install()
1422-
>>> _('hello_world'))
1423-
你好,世界!
1422+
>>> _('hello_world')
1423+
'你好,世界!'
14241424
>>>
14251425
>>> en_trans.install()
14261426
>>> _('hello_world')
1427-
Hello, world!
1427+
'Hello, world!'
14281428
```
14291429

14301430
## turtle
@@ -1796,14 +1796,10 @@ True
17961796
#### importer
17971797

17981798
```python
1799-
>>> import zipimport
1800-
>>> zip = zipimport.zipimporter("g.zip")
1801-
>>> zip.archive
1802-
'g.zip'
1803-
>>>
1804-
>>> a = zip.load_module("a")
1805-
>>> a
1806-
<module 'a' from 'D:\\GitHub\\python-cheatsheet-redefined\\test_env\\g.zip\\a.py'>
1799+
>>> # the zipimport module is not explicitly used
1800+
>>> import sys
1801+
>>> sys.path.insert(0, 'g.zip')
1802+
>>> import a
18071803
>>> a.main()
18081804
Hello everyone
18091805
```

README.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Fork me on [GitHub](https://github.com/pynickle/python-cheatsheet-redefined).
108108

109109
```python
110110
>>> import string
111-
111+
>>>
112112
>>> # not locale-dependent
113113
>>> string.ascii_letters
114114
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -959,7 +959,7 @@ pickle A
959959
>>> import shelve
960960
>>>
961961
>>> # Open a shelf file (creates if not exists)
962-
>>> with shelve.open('geenrated/mydata.db') as db:
962+
>>> with shelve.open('generated/mydata.db') as db:
963963
... # Basic operations: set, get, delete, check existence
964964
... db['name'] = 'Alice'
965965
... db['numbers'] = [1, 2, 3]
@@ -978,12 +978,12 @@ pickle A
978978
... # Sync to ensure data is written to disk
979979
... db.sync()
980980
...
981-
Alice
981+
'Alice'
982982
True
983983
['name', 'numbers']
984984
>>>
985985
>>> # Re-open with writeback=True for direct modification
986-
>>> db = shelve.open('mydata.db', writeback = True)
986+
>>> db = shelve.open('generated/mydata.db', writeback = True)
987987
>>> db['numbers'].append(5) # Direct modify (auto-persisted on close)
988988
>>> db['numbers']
989989
[1, 2, 3, 4, 5]
@@ -1401,31 +1401,31 @@ _wave_params(nchannels=2, sampwidth=2, framerate=44100, nframes=442368, comptype
14011401
>>>
14021402
>>> zh_trans = gettext.translation(
14031403
... DOMAIN,
1404-
... localedir=LOCALE_DIR,
1405-
... languages=['zh'],
1406-
... fallback=True # 找不到 .mo 时不报错
1404+
... localedir = LOCALE_DIR,
1405+
... languages = ['zh'],
1406+
... fallback = True
14071407
... )
14081408
>>>
14091409
>>> en_trans = gettext.translation(
14101410
... DOMAIN,
1411-
... localedir=LOCALE_DIR,
1412-
... languages=['en'],
1413-
... fallback=True
1411+
... localedir = LOCALE_DIR,
1412+
... languages = ['en'],
1413+
... fallback = True
14141414
... )
14151415
>>>
14161416
>>> _zh = zh_trans.gettext # Get the specific gettext function from the instance
14171417
>>> _zh('hello_world')
1418-
你好,世界!
1418+
'你好,世界!'
14191419
>>>
14201420
>>> # Install the Chinese translation globally
14211421
>>> # This sets the global _() function for all modules to use zh_trans.
14221422
>>> zh_trans.install()
1423-
>>> _('hello_world'))
1424-
你好,世界!
1423+
>>> _('hello_world')
1424+
'你好,世界!'
14251425
>>>
14261426
>>> en_trans.install()
14271427
>>> _('hello_world')
1428-
Hello, world!
1428+
'Hello, world!'
14291429
```
14301430

14311431
## turtle
@@ -1797,14 +1797,10 @@ True
17971797
#### importer
17981798

17991799
```python
1800-
>>> import zipimport
1801-
>>> zip = zipimport.zipimporter("g.zip")
1802-
>>> zip.archive
1803-
'g.zip'
1804-
>>>
1805-
>>> a = zip.load_module("a")
1806-
>>> a
1807-
<module 'a' from 'D:\\GitHub\\python-cheatsheet-redefined\\test_env\\g.zip\\a.py'>
1800+
>>> # the zipimport module is not explicitly used
1801+
>>> import sys
1802+
>>> sys.path.insert(0, 'g.zip')
1803+
>>> import a
18081804
>>> a.main()
18091805
Hello everyone
18101806
```

test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
]
2020
NOTEST_2 = ["del c", "list(p.glob('**/*.py'))", "name", "c = pickle.dumps(a)",
2121
"password", "a.timeit(number = 1000)", "foo()",
22-
'cmd("python argparse_example.py --help")'
22+
'cmd("python argparse_example.py --help")', 'msg.as_string()[:500]',
23+
"_('hello_world')"
2324
]
2425

2526

@@ -79,7 +80,6 @@ def main(file_name):
7980
code = code.replace(first, "").replace(second, "")
8081
return code
8182

82-
8383
if __name__ == "__main__":
8484
code = main("../README.md")
8585
doctest.run_docstring_examples(code, None)

test_env/mydata.db

12 KB
Binary file not shown.

test_env/test.py

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)