Esempio n. 1
0
 def test_restart(self, serial_ports, serial, monkeypatch,
                  mock_version_response):
     """Should pass the call through."""
     restart = Mock()
     monkeypatch.setattr(NodeMCU, "restart", restart)
     assert main("--restart".split()) == 0
     restart.assert_called_once_with()
Esempio n. 2
0
 def test_move(self, serial_ports, serial, monkeypatch,
               mock_version_response):
     """Should pass the call through."""
     rename_file = Mock()
     monkeypatch.setattr(NodeMCU, "rename_file", rename_file)
     assert main("--rename foo.txt bar.txt".split()) == 0
     rename_file.assert_called_once_with("foo.txt", "bar.txt")
Esempio n. 3
0
 def test_move(self, serial_ports, serial, monkeypatch,
               mock_version_response):
     """Should pass the call through."""
     rename_file = Mock()
     monkeypatch.setattr(NodeMCU, "rename_file", rename_file)
     assert main("--rename foo.txt bar.txt".split()) == 0
     rename_file.assert_called_once_with("foo.txt", "bar.txt")
Esempio n. 4
0
 def test_restart(self, serial_ports, serial, monkeypatch,
                  mock_version_response):
     """Should pass the call through."""
     restart = Mock()
     monkeypatch.setattr(NodeMCU, "restart", restart)
     assert main("--restart".split()) == 0
     restart.assert_called_once_with()
Esempio n. 5
0
    def test_list_empty(self, serial_ports, serial, monkeypatch,
                        mock_version_response, capsys):
        """Special case shouldn't break."""
        monkeypatch.setattr(NodeMCU, "list_files", Mock(return_value={}))
        assert main("--list".split()) == 0

        # NB: Aligned columns
        out, err = capsys.readouterr()
        assert out == "Total: 0 files, 0 bytes.\n"
Esempio n. 6
0
    def test_list_empty(self, serial_ports, serial, monkeypatch,
                        mock_version_response, capsys):
        """Special case shouldn't break."""
        monkeypatch.setattr(NodeMCU, "list_files", Mock(return_value={}))
        assert main("--list".split()) == 0

        # NB: Aligned columns
        out, err = capsys.readouterr()
        assert out == "Total: 0 files, 0 bytes.\n"
Esempio n. 7
0
    def test_dofile(self, serial_ports, serial, monkeypatch,
                    mock_version_response, capfd):
        """Dofile should run and the output printed."""
        dofile = Mock(return_value=b"hello, there!\r\n")
        monkeypatch.setattr(NodeMCU, "dofile", dofile)
        assert main("--dofile foo.lua".split()) == 0
        dofile.assert_called_once_with("foo.lua")

        out, err = capfd.readouterr()
        assert out == "hello, there!\r\n"  # XXX: capfd always gives a string
Esempio n. 8
0
    def test_read(self, serial_ports, serial, monkeypatch,
                  mock_version_response, capfd):
        """Reads should be passed through."""
        read_file = Mock(return_value=b"foo")
        monkeypatch.setattr(NodeMCU, "read_file", read_file)
        assert main("--read foo.txt".split()) == 0
        read_file.assert_called_once_with("foo.txt")

        out, err = capfd.readouterr()
        assert out == "foo"  # XXX: capfd always gives a string...
Esempio n. 9
0
    def test_dofile(self, serial_ports, serial, monkeypatch,
                    mock_version_response, capfd):
        """Dofile should run and the output printed."""
        dofile = Mock(return_value=b"hello, there!\r\n")
        monkeypatch.setattr(NodeMCU, "dofile", dofile)
        assert main("--dofile foo.lua".split()) == 0
        dofile.assert_called_once_with("foo.lua")

        out, err = capfd.readouterr()
        assert out == "hello, there!\r\n"  # XXX: capfd always gives a string
Esempio n. 10
0
    def test_read(self, serial_ports, serial, monkeypatch,
                  mock_version_response, capfd):
        """Reads should be passed through."""
        read_file = Mock(return_value=b"foo")
        monkeypatch.setattr(NodeMCU, "read_file", read_file)
        assert main("--read foo.txt".split()) == 0
        read_file.assert_called_once_with("foo.txt")

        out, err = capfd.readouterr()
        assert out == "foo"  # XXX: capfd always gives a string...
Esempio n. 11
0
    def test_list_singletons(self, serial_ports, serial, monkeypatch,
                             mock_version_response, capsys):
        """Grammar should be correct..."""
        files = {
            "a.txt": 1,
        }
        monkeypatch.setattr(NodeMCU, "list_files", Mock(return_value=files))
        assert main("--list".split()) == 0

        # NB: Aligned columns
        out, err = capsys.readouterr()
        assert out == "Total: 1 file, 1 byte.\na.txt  1\n"
Esempio n. 12
0
    def test_list_singletons(self, serial_ports, serial, monkeypatch,
                             mock_version_response, capsys):
        """Grammar should be correct..."""
        files = {
            "a.txt": 1,
        }
        monkeypatch.setattr(NodeMCU, "list_files", Mock(return_value=files))
        assert main("--list".split()) == 0

        # NB: Aligned columns
        out, err = capsys.readouterr()
        assert out == "Total: 1 file, 1 byte.\na.txt  1\n"
Esempio n. 13
0
    def test_write(self, serial_ports, serial, monkeypatch,
                   mock_version_response):
        """Writes should be passed through."""
        import sys

        # Mock stdin
        stdin = Mock(read=Mock(return_value=b"foo"))
        stdin.return_value = stdin
        stdin.buffer = stdin
        monkeypatch.setattr(sys, "stdin", stdin)

        write_file = Mock()
        monkeypatch.setattr(NodeMCU, "write_file", write_file)
        assert main("--write foo.txt".split()) == 0
        write_file.assert_called_once_with("foo.txt", b"foo")
Esempio n. 14
0
    def test_write(self, serial_ports, serial, monkeypatch,
                   mock_version_response):
        """Writes should be passed through."""
        import sys

        # Mock stdin
        stdin = Mock(read=Mock(return_value=b"foo"))
        stdin.return_value = stdin
        stdin.buffer = stdin
        monkeypatch.setattr(sys, "stdin", stdin)

        write_file = Mock()
        monkeypatch.setattr(NodeMCU, "write_file", write_file)
        assert main("--write foo.txt".split()) == 0
        write_file.assert_called_once_with("foo.txt", b"foo")
Esempio n. 15
0
    def test_list(self, serial_ports, serial, monkeypatch,
                  mock_version_response, capsys):
        """File listings should be formatted nicely."""
        files = {
            "a.txt": 123,
            "bb.txt": 321,
        }
        monkeypatch.setattr(NodeMCU, "list_files", Mock(return_value=files))
        assert main("--list".split()) == 0

        # NB: Aligned columns
        out, err = capsys.readouterr()
        assert out in (
            "Total: 2 files, 444 bytes.\na.txt   123\nbb.txt  321\n",
            "Total: 2 files, 444 bytes.\nbb.txt  321\na.txt   123\n",
        )
Esempio n. 16
0
    def test_list(self, serial_ports, serial, monkeypatch,
                  mock_version_response, capsys):
        """File listings should be formatted nicely."""
        files = {
            "a.txt": 123,
            "bb.txt": 321,
        }
        monkeypatch.setattr(NodeMCU, "list_files", Mock(return_value=files))
        assert main("--list".split()) == 0

        # NB: Aligned columns
        out, err = capsys.readouterr()
        assert out in (
            "Total: 2 files, 444 bytes.\na.txt   123\nbb.txt  321\n",
            "Total: 2 files, 444 bytes.\nbb.txt  321\na.txt   123\n",
        )
Esempio n. 17
0
 def test_no_ports_available(self, no_serial_ports, serial):
     """If no ports are available and none are specified, everything should
     fail."""
     with pytest.raises(SystemExit):
         main("--list".split())
Esempio n. 18
0
 def test_manual_baudrate(self, serial_ports, serial, mock_format_response):
     """Baudrate should be overrideable."""
     main("--baudrate 115200 --format".split())
     serial.assert_called_once_with("/dev/ttyUSB5", 115200, timeout=2.0)
Esempio n. 19
0
 def test_bad_version(self, serial_ports, serial, monkeypatch, version):
     """Incompatible versions should fail."""
     monkeypatch.setattr(NodeMCU, "get_version", Mock(return_value=version))
     with pytest.raises(ValueError):
         main("--format".split())
Esempio n. 20
0
 def test_manual_port_overrides(self, serial_ports, serial,
                                mock_format_response):
     """Specifying a port should override the default one."""
     main("--port /dev/null --format".split())
     serial.assert_called_once_with("/dev/null", 9600, timeout=2.0)
Esempio n. 21
0
 def test_sensible_port(self, serial_ports, serial, mock_format_response):
     """If several ports are available, select /dev/ttyUSB* by preference.
     """
     main("--format".split())
     serial.assert_called_once_with("/dev/ttyUSB5", 9600, timeout=2.0)
Esempio n. 22
0
 def test_manual_port(self, no_serial_ports, serial, mock_format_response):
     """If no ports are available specifying a port will fix things."""
     main("--port /dev/null --format".split())
     serial.assert_called_once_with("/dev/null", 9600, timeout=2.0)
Esempio n. 23
0
 def test_bad_version(self, serial_ports, serial, monkeypatch, version):
     """Incompatible versions should fail."""
     monkeypatch.setattr(NodeMCU, "get_version", Mock(return_value=version))
     with pytest.raises(ValueError):
         main("--format".split())
Esempio n. 24
0
 def test_manual_port_overrides(self, serial_ports, serial,
                                mock_format_response):
     """Specifying a port should override the default one."""
     main("--port /dev/null --format".split())
     serial.assert_called_once_with("/dev/null", 9600, timeout=2.0)
Esempio n. 25
0
 def test_sensible_port(self, serial_ports, serial, mock_format_response):
     """If several ports are available, select /dev/ttyUSB* by preference.
     """
     main("--format".split())
     serial.assert_called_once_with("/dev/ttyUSB5", 9600, timeout=2.0)
Esempio n. 26
0
 def test_manual_baudrate(self, serial_ports, serial, mock_format_response):
     """Baudrate should be overrideable."""
     main("--baudrate 115200 --format".split())
     serial.assert_called_once_with("/dev/ttyUSB5", 115200, timeout=2.0)
Esempio n. 27
0
 def test_no_ports_available(self, no_serial_ports, serial):
     """If no ports are available and none are specified, everything should
     fail."""
     with pytest.raises(SystemExit):
         main("--list".split())
Esempio n. 28
0
 def test_manual_port(self, no_serial_ports, serial, mock_format_response):
     """If no ports are available specifying a port will fix things."""
     main("--port /dev/null --format".split())
     serial.assert_called_once_with("/dev/null", 9600, timeout=2.0)
Esempio n. 29
0
 def test_bad_arguments(self, args, serial_ports, serial):
     """Make sure various obvious bad arguments make the parser crash."""
     with pytest.raises(SystemExit):
         main(args.split())
Esempio n. 30
0
 def test_bad_arguments(self, args, serial_ports, serial):
     """Make sure various obvious bad arguments make the parser crash."""
     with pytest.raises(SystemExit):
         main(args.split())