示例#1
0
    def test_converging(self):
        """Test it converges."""
        desk = Desk({"back-of-desk": [[0, 4]], "monitor": [[9, 7], [6, 5]]})
        desk.pixels = MagicMock()
        converge = Converge(desk, [0, 255, 0])
        converge.run()

        desk.pixels.assert_has_calls(
            [
                call.__setitem__(0, [0, 255, 0]),
                call.__setitem__(5, [0, 255, 0]),
                call.show(),
                call.__setitem__(1, [0, 255, 0]),
                call.__setitem__(6, [0, 255, 0]),
                call.show(),
                call.__setitem__(2, [0, 255, 0]),
                call.__setitem__(7, [0, 255, 0]),
                call.show(),
                call.__setitem__(3, [0, 255, 0]),
                call.__setitem__(8, [0, 255, 0]),
                call.show(),
                call.__setitem__(4, [0, 255, 0]),
                call.__setitem__(9, [0, 255, 0]),
                call.show(),
            ]
        )
示例#2
0
def test_generate_users(monkeypatch, capsys):
    mocked_api = Mock()
    monkeypatch.setattr('koneko.lscat.api', mocked_api)
    monkeypatch.setattr('koneko.Terminal.width', 100)
    monkeypatch.setattr('koneko.Terminal.height', 20)
    monkeypatch.setattr('koneko.config.api.users_page_spacing', lambda: 1)
    monkeypatch.setattr('koneko.config.api.use_ueberzug', lambda: False)

    test_pics = [f"{str(idx).rjust(3, '0')}_test" for idx in list(range(120))]

    gen = lscat.generate_users(Path('.'))  # Path doesn't matter
    gen.send(None)

    # No need to shuffle, tracker already shuffles
    for pic in test_pics:
        gen.send(pic)
        gen.send(None)

    assert mocked_api.mock_calls[:4] == [
        call.show(Path('000_test'), 2, 0, 310),
        call.show(Path('001_test'), 39, 0, 310),
        call.show(Path('002_test'), 57, 0, 310),
        call.show(Path('003_test'), 75, 0, 310),
    ]

    captured = capsys.readouterr()
    assert captured.out == '                  00\n                  test\n\n\n                  04\n                  test\n\n\n                  08\n                  test\n\n\n                  12\n                  test\n\n\n                  16\n                  test\n\n\n                  20\n                  test\n\n\n                  24\n                  test\n\n\n                  28\n                  test\n\n\n                  32\n                  test\n\n\n                  36\n                  test\n\n\n                  40\n                  test\n\n\n                  44\n                  test\n\n\n                  48\n                  test\n\n\n                  52\n                  test\n\n\n                  56\n                  test\n\n\n                  60\n                  test\n\n\n                  64\n                  test\n\n\n                  68\n                  test\n\n\n                  72\n                  test\n\n\n                  76\n                  test\n\n\n                  80\n                  test\n\n\n                  84\n                  test\n\n\n                  88\n                  test\n\n\n                  92\n                  test\n\n\n                  96\n                  test\n\n\n                  00\n                  test\n\n\n                  04\n                  test\n\n\n                  08\n                  test\n\n\n                  12\n                  test\n\n\n                  16\n                  test\n\n\n'
    def test_reverse_sweeping(self):
        """Test it sweeps backwards."""
        desk = Desk({"back-of-desk": [[0, 4]], "monitor": [[9, 7], [6, 5]]})
        desk.pixels = MagicMock()
        sweep = Sweep(desk, [0, 255, 0], {"direction": "backwards"})
        sweep.run()

        desk.pixels.assert_has_calls([
            call.__setitem__(5, [0, 255, 0]),
            call.show(),
            call.__setitem__(6, [0, 255, 0]),
            call.show(),
            call.__setitem__(7, [0, 255, 0]),
            call.show(),
            call.__setitem__(8, [0, 255, 0]),
            call.show(),
            call.__setitem__(9, [0, 255, 0]),
            call.show(),
            call.__setitem__(4, [0, 255, 0]),
            call.show(),
            call.__setitem__(3, [0, 255, 0]),
            call.show(),
            call.__setitem__(2, [0, 255, 0]),
            call.show(),
            call.__setitem__(1, [0, 255, 0]),
            call.show(),
            call.__setitem__(0, [0, 255, 0]),
            call.show(),
        ])
示例#4
0
def test_generate_users_ueberzug(monkeypatch, capsys):
    mocked_api = Mock()
    monkeypatch.setattr('koneko.lscat.api', mocked_api)
    monkeypatch.setattr('koneko.Terminal.width', 100)
    monkeypatch.setattr('koneko.Terminal.height', 20)
    monkeypatch.setattr('koneko.config.api.users_page_spacing', lambda: 1)
    monkeypatch.setattr('koneko.config.api.use_ueberzug', lambda: True)

    test_pics = [f"{str(idx).rjust(3, '0')}_test" for idx in list(range(120))]

    gen = lscat.generate_users_ueberzug(Path('.'))  # Path doesn't matter
    gen.send(None)

    # No need to shuffle, tracker already shuffles
    for pic in test_pics:
        gen.send(pic)
        gen.send(None)

    assert mocked_api.mock_calls == [
        call.show(Path('000_test'), 2, 0, 310),
        call.show(Path('001_test'), 39, 0, 310),
        call.show(Path('002_test'), 57, 0, 310),
        call.show(Path('003_test'), 75, 0, 310),
        call.show(Path('004_test'), 2, 9, 310),
        call.show(Path('005_test'), 39, 9, 310),
        call.show(Path('006_test'), 57, 9, 310),
        call.show(Path('007_test'), 75, 9, 310)
    ]

    captured = capsys.readouterr()
    assert captured.out == '                  00\n                  test\n\n\n\n\n\n\n\n\n\n                  04\n                  test\n'
示例#5
0
def test_generate_previews(monkeypatch):
    monkeypatch.setattr('koneko.config.api.use_ueberzug', lambda: True)
    mocked_api = Mock()
    monkeypatch.setattr('koneko.lscat.api', mocked_api)
    monkeypatch.setattr('koneko.Terminal.width', 100)
    monkeypatch.setattr('koneko.Terminal.height', 20)

    test_pics = [f"12345_p{idx}_master1200.jpg" for idx in list(range(10))]

    gen = lscat.generate_previews(Path('.'), 10)  # Path doesn't matter
    gen.send(None)

    # No need to shuffle, tracker already shuffles
    for pic in test_pics:
        gen.send(pic)
        gen.send(None)

    assert mocked_api.mock_calls == [
        call.show(Path('12345_p0_master1200.jpg'), 2, 0, 310),
        call.show(Path('12345_p1_master1200.jpg'), 2, 9, 310),
        call.show(Path('12345_p2_master1200.jpg'), 74, 0, 310),
        call.show(Path('12345_p3_master1200.jpg'), 74, 9, 310),
    ]
示例#6
0
def test_generate_page(monkeypatch, capsys):
    mocked_api = Mock()
    monkeypatch.setattr('koneko.lscat.api', mocked_api)
    monkeypatch.setattr('koneko.Terminal.width', 100)
    monkeypatch.setattr('koneko.Terminal.height', 20)
    monkeypatch.setattr('koneko.config.api.page_spacing', lambda: 1)
    monkeypatch.setattr('koneko.config.api.use_ueberzug', lambda: False)

    test_pics = [f"{str(idx).rjust(3, '0')}_test" for idx in list(range(30))]

    gen = lscat.generate_page(Path('.'))  # Path doesn't matter
    gen.send(None)

    # No need to shuffle, tracker already shuffles
    for pic in test_pics:
        gen.send(pic)
        gen.send(None)

    assert mocked_api.mock_calls[:10] == [
        call.show(Path('000_test'), 2, 0, 310),
        call.show(Path('001_test'), 20, 0, 310),
        call.show(Path('002_test'), 38, 0, 310),
        call.show(Path('003_test'), 56, 0, 310),
        call.show(Path('004_test'), 74, 0, 310),
        call.show(Path('005_test'), 2, 9, 310),
        call.show(Path('006_test'), 20, 9, 310),
        call.show(Path('007_test'), 38, 9, 310),
        call.show(Path('008_test'), 56, 9, 310),
        call.show(Path('009_test'), 74, 9, 310)
    ]
    assert mocked_api.mock_calls[-10:] == [
        call.show(Path('020_test'), 2, 0, 310),
        call.show(Path('021_test'), 20, 0, 310),
        call.show(Path('022_test'), 38, 0, 310),
        call.show(Path('023_test'), 56, 0, 310),
        call.show(Path('024_test'), 74, 0, 310),
        call.show(Path('025_test'), 2, 9, 310),
        call.show(Path('026_test'), 20, 9, 310),
        call.show(Path('027_test'), 38, 9, 310),
        call.show(Path('028_test'), 56, 9, 310),
        call.show(Path('029_test'), 74, 9, 310)
    ]
示例#7
0
    def testTest(self):
        """Check test method"""
        """
        1) test if messageBox.warning is called
        2) open test selector widget
            2.1) cancel => do nothing
            2.2) ok =>
                2.2.1) Create TesterWidget and dock it
                2.2.2) load tests in it
                2.2.3) start running test
        """
        qwidget = mock.Mock(spec=QWidget)
        qwidget.isVisible.return_value = True
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        testerPlugin.widget = qwidget
        qmessageboxMock = mock.Mock(spec=QMessageBox.warning)
        with mock.patch('PyQt5.QtWidgets.QMessageBox.warning',
                        qmessageboxMock):
            testerPlugin.test()
        self.assertEqual('Tester plugin', str(qmessageboxMock.call_args[0][1]))
        self.assertEqual('A test cycle is currently being run',
                         str(qmessageboxMock.call_args[0][2]))

        # test 2.1
        dlgMock = mock.Mock()
        dlgMock.tests = None
        testselectorMock = mock.Mock(spec=qgistester.testselector.TestSelector,
                                     return_value=dlgMock)
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        # needed to go through the first tested if condition
        testerPlugin.widget = None
        with mock.patch('qgistester.plugin.TestSelector', testselectorMock):
            testerPlugin.test()
        self.assertIsNone(testerPlugin.widget)

        # test 2.2 and 2.3
        self.IFACE_Mock.reset_mock
        testselectorMock.reset_mock
        dlgMock.reset_mock
        mytest = Test('some tests')
        mytest.settings = {}
        dlgMock.tests = [mytest]
        testerwidgetMock = mock.Mock(spec=qgistester.testerwidget.TesterWidget,
                                     return_value=dlgMock)
        testerPlugin = TesterPlugin(self.IFACE_Mock)
        # needed to go through the first tested if condition
        testerPlugin.widget = None
        with mock.patch('qgistester.plugin.TestSelector', testselectorMock):
            with mock.patch('qgistester.plugin.TesterWidget',
                            testerwidgetMock):
                testerPlugin.test()
        self.assertIsNotNone(testerPlugin.widget)
        self.assertIn('call.addDockWidget',
                      str(testerPlugin.iface.mock_calls[-1]))
        expected = [
            call.exec_(),
            call.exec_(),
            call.testingFinished.connect(testerPlugin.testingFinished),
            call.show(),
            call.setTests([mytest]),
            call.startTesting()
        ]
        self.assertEqual(dlgMock.mock_calls, expected)
示例#8
0
 def test_fill(self):
     """Test we can fill all the pixels."""
     desk = Desk({"foo": [[0, 19]]})
     desk.pixels = MagicMock()
     desk.fill([255, 0, 0])
     desk.pixels.assert_has_calls([call.fill([255, 0, 0]), call.show()])