2 from ..build
.plat
import *
6 class MockPlatform(Platform
):
12 def toolchain_prepare(self
, fragment
, name
, **kwargs
):
13 raise NotImplementedError
16 class PlatformTestCase(FHDLTestCase
):
18 self
.platform
= MockPlatform()
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")
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")
28 def test_add_file_exact_duplicate(self
):
29 self
.platform
.add_file("x.txt", b
"foo")
30 self
.platform
.add_file("x.txt", b
"foo")
32 def test_add_file_io(self
):
33 with
open(__file__
) as f
:
34 self
.platform
.add_file("x.txt", f
)
35 with
open(__file__
) as f
:
36 self
.assertEqual(self
.platform
.extra_files
["x.txt"], f
.read())
38 def test_add_file_wrong_filename(self
):
39 with self
.assertRaisesRegex(TypeError,
40 r
"^File name must be a string, not 1$"):
41 self
.platform
.add_file(1, "")
43 def test_add_file_wrong_contents(self
):
44 with self
.assertRaisesRegex(TypeError,
45 r
"^File contents must be str, bytes, or a file-like object, not 1$"):
46 self
.platform
.add_file("foo", 1)
48 def test_add_file_wrong_duplicate(self
):
49 self
.platform
.add_file("foo", "")
50 with self
.assertRaisesRegex(ValueError,
51 r
"^File 'foo' already exists$"):
52 self
.platform
.add_file("foo", "bar")