|
| 1 | +from .. import * |
| 2 | +from ..build.plat import * |
| 3 | +from .utils import * |
| 4 | + |
| 5 | + |
| 6 | +class MockPlatform(Platform): |
| 7 | + resources = [] |
| 8 | + connectors = [] |
| 9 | + |
| 10 | + required_tools = [] |
| 11 | + |
| 12 | + def toolchain_prepare(self, fragment, name, **kwargs): |
| 13 | + raise NotImplementedError |
| 14 | + |
| 15 | + |
| 16 | +class PlatformTestCase(FHDLTestCase): |
| 17 | + def setUp(self): |
| 18 | + self.platform = MockPlatform() |
| 19 | + |
| 20 | + def test_add_file_str(self): |
| 21 | + self.platform.add_file("x.txt", "foo") |
| 22 | + self.assertEqual(self.platform.extra_files["x.txt"], "foo") |
| 23 | + |
| 24 | + def test_add_file_bytes(self): |
| 25 | + self.platform.add_file("x.txt", b"foo") |
| 26 | + self.assertEqual(self.platform.extra_files["x.txt"], b"foo") |
| 27 | + |
| 28 | + def test_add_file_io(self): |
| 29 | + with open(__file__) as f: |
| 30 | + self.platform.add_file("x.txt", f) |
| 31 | + with open(__file__) as f: |
| 32 | + self.assertEqual(self.platform.extra_files["x.txt"], f.read()) |
| 33 | + |
| 34 | + def test_add_file_wrong_filename(self): |
| 35 | + with self.assertRaises(TypeError, |
| 36 | + msg="File name must be a string, not 1"): |
| 37 | + self.platform.add_file(1, "") |
| 38 | + |
| 39 | + def test_add_file_wrong_contents(self): |
| 40 | + with self.assertRaises(TypeError, |
| 41 | + msg="File contents must be str, bytes, or a file-like object, not 1"): |
| 42 | + self.platform.add_file("foo", 1) |
| 43 | + |
| 44 | + def test_add_file_wrong_duplicate(self): |
| 45 | + self.platform.add_file("foo", "") |
| 46 | + with self.assertRaises(ValueError, |
| 47 | + msg="File 'foo' already exists"): |
| 48 | + self.platform.add_file("foo", "bar") |
0 commit comments