| 1 | import os |
| 2 | import sys |
| 3 | import tempfile |
| 4 | import unittest |
| 5 | |
| 6 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 7 | |
| 8 | from textload import load_text |
| 9 | |
| 10 | |
| 11 | class TestLoadText(unittest.TestCase): |
| 12 | def test_plain_file(self): |
| 13 | with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False, encoding="utf-8") as f: |
| 14 | f.write("hello") |
| 15 | path = f.name |
| 16 | self.assertEqual(load_text(path), "hello") |
| 17 | |
| 18 | def test_bom_file(self): |
| 19 | with tempfile.NamedTemporaryFile(mode="wb", suffix=".txt", delete=False) as f: |
| 20 | f.write(b"\xef\xbb\xbfhello") |
| 21 | path = f.name |
| 22 | self.assertEqual(load_text(path), "hello") |
| 23 | |
| 24 | |
| 25 | if __name__ == "__main__": |
| 26 | unittest.main() |
| 27 |