Exemple #1
0
    def test_read_file_not_exists(self):
        """Files which can't be opened for read cause an error."""
        s = MockSerial([b"",
                        # Close existing file
                        b"file.close()\r\n",
                        b"file.close()\r\n",
                        # Check for existance of the file
                        b"=file.list()['test.txt']\r\n",
                        b"=file.list()['test.txt']\r\nnil\r\n"])
        n = NodeMCU(s)

        with pytest.raises(IOError):
            n.read_file("test.txt")

        assert s.finished
Exemple #2
0
    def test_read_file(self):
        """Reading should proceed block-by-block."""
        s = MockSerial([
            b"",
            # Close existing file
            b"file.close()\r\n",
            b"file.close()\r\n",
            # Check for existance of the file
            b"=file.list()['test.txt']\r\n",
            b"=file.list()['test.txt']\r\n3\r\n",
            # Open the file for read
            b"=file.open('test.txt', 'r')\r\n",
            b"=file.open('test.txt', 'r')\r\ntrue\r\n",
            # Read a block
            b"uart.write(0, file.read(2))\r\n",
            b"uart.write(0, file.read(2))\r\n\x01\x02",
            # Read last block
            b"uart.write(0, file.read(1))\r\n",
            b"uart.write(0, file.read(1))\r\n\x03",
            # Close the file
            b"file.close()\r\n",
            b"file.close()\r\n"
        ])
        n = NodeMCU(s)

        assert n.read_file("test.txt", 2) == b"\x01\x02\x03"

        assert s.finished
Exemple #3
0
    def test_read_file(self):
        """Reading should proceed block-by-block."""
        s = MockSerial([b"",
                        # Close existing file
                        b"file.close()\r\n",
                        b"file.close()\r\n",
                        # Check for existance of the file
                        b"=file.list()['test.txt']\r\n",
                        b"=file.list()['test.txt']\r\n3\r\n",
                        # Open the file for read
                        b"=file.open('test.txt', 'r')\r\n",
                        b"=file.open('test.txt', 'r')\r\ntrue\r\n",
                        # Read a block
                        b"uart.write(0, file.read(2))\r\n",
                        b"uart.write(0, file.read(2))\r\n\x01\x02",
                        # Read last block
                        b"uart.write(0, file.read(1))\r\n",
                        b"uart.write(0, file.read(1))\r\n\x03",
                        # Close the file
                        b"file.close()\r\n",
                        b"file.close()\r\n"])
        n = NodeMCU(s)

        assert n.read_file("test.txt", 2) == b"\x01\x02\x03"

        assert s.finished
Exemple #4
0
    def test_read_file_not_exists(self):
        """Files which can't be opened for read cause an error."""
        s = MockSerial([
            b"",
            # Close existing file
            b"file.close()\r\n",
            b"file.close()\r\n",
            # Check for existance of the file
            b"=file.list()['test.txt']\r\n",
            b"=file.list()['test.txt']\r\nnil\r\n"
        ])
        n = NodeMCU(s)

        with pytest.raises(IOError):
            n.read_file("test.txt")

        assert s.finished