| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 979f239 commit dd596b4
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,14 @@ | |||
| 1 | - import os | ||
| 1 | + import tempfile | ||
| 2 | 2 | import unittest | |
| 3 | + from pathlib import Path | ||
| 3 | 4 | ||
| 4 | 5 | from bpython.config import getpreferredencoding | |
| 5 | 6 | from bpython.history import History | |
| 6 | 7 | ||
| 7 | 8 | ||
| 8 | 9 | class TestHistory(unittest.TestCase): | |
| 9 | 10 | def setUp(self): | |
| 10 | - self.history = History("#%d" % x for x in range(1000)) | ||
| 11 | + self.history = History(f"#{x}" for x in range(1000)) | ||
| 11 | 12 | ||
| 12 | 13 | def test_is_at_start(self): | |
| 13 | 14 | self.history.first() | |
@@ -84,7 +85,8 @@ def test_reset(self): | |||
| 84 | 85 | ||
| 85 | 86 | class TestHistoryFileAccess(unittest.TestCase): | |
| 86 | 87 | def setUp(self): | |
| 87 | - self.filename = "history_temp_file" | ||
| 88 | + self.tempdir = tempfile.TemporaryDirectory() | ||
| 89 | + self.filename = str(Path(self.tempdir.name) / "history_temp_file") | ||
| 88 | 90 | self.encoding = getpreferredencoding() | |
| 89 | 91 | ||
| 90 | 92 | with open( | |
@@ -109,21 +111,17 @@ def test_append_reload_and_write(self): | |||
| 109 | 111 | ||
| 110 | 112 | def test_save(self): | |
| 111 | 113 | history = History() | |
| 112 | - history.entries = [] | ||
| 113 | - for line in ["#1", "#2", "#3", "#4"]: | ||
| 114 | + for line in ("#1", "#2", "#3", "#4"): | ||
| 114 | 115 | history.append_to(history.entries, line) | |
| 115 | 116 | ||
| 116 | 117 | # save only last 2 lines | |
| 117 | 118 | history.save(self.filename, self.encoding, lines=2) | |
| 118 | 119 | ||
| 119 | - # empty the list of entries and load again from the file | ||
| 120 | - history.entries = [""] | ||
| 120 | + # load again from the file | ||
| 121 | + history = History() | ||
| 121 | 122 | history.load(self.filename, self.encoding) | |
| 122 | 123 | ||
| 123 | 124 | self.assertEqual(history.entries, ["#3", "#4"]) | |
| 124 | 125 | ||
| 125 | 126 | def tearDown(self): | |
| 126 | - try: | ||
| 127 | - os.remove(self.filename) | ||
| 128 | - except OSError: | ||
| 129 | - pass | ||
| 127 | + self.tempdir = None | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments