2 from nmigen
.build
.plat
import *
7 class MockPlatform(Platform
):
13 def toolchain_prepare(self
, fragment
, name
, **kwargs
):
14 raise NotImplementedError
17 class PlatformTestCase(FHDLTestCase
):
19 self
.platform
= MockPlatform()
21 def test_add_file_str(self
):
22 self
.platform
.add_file("x.txt", "foo")
23 self
.assertEqual(self
.platform
.extra_files
["x.txt"], "foo")
25 def test_add_file_bytes(self
):
26 self
.platform
.add_file("x.txt", b
"foo")
27 self
.assertEqual(self
.platform
.extra_files
["x.txt"], b
"foo")
29 def test_add_file_exact_duplicate(self
):
30 self
.platform
.add_file("x.txt", b
"foo")
31 self
.platform
.add_file("x.txt", b
"foo")
33 def test_add_file_io(self
):
34 with
open(__file__
) as f
:
35 self
.platform
.add_file("x.txt", f
)
36 with
open(__file__
) as f
:
37 self
.assertEqual(self
.platform
.extra_files
["x.txt"], f
.read())
39 def test_add_file_wrong_filename(self
):
40 with self
.assertRaisesRegex(TypeError,
41 r
"^File name must be a string, not 1$"):
42 self
.platform
.add_file(1, "")
44 def test_add_file_wrong_contents(self
):
45 with self
.assertRaisesRegex(TypeError,
46 r
"^File contents must be str, bytes, or a file-like object, not 1$"):
47 self
.platform
.add_file("foo", 1)
49 def test_add_file_wrong_duplicate(self
):
50 self
.platform
.add_file("foo", "")
51 with self
.assertRaisesRegex(ValueError,
52 r
"^File 'foo' already exists$"):
53 self
.platform
.add_file("foo", "bar")