Пример #1
0
    def test02_init(self):
        configIns = config.Config(self.configfile)
        self.assertIsInstance(configIns, config.Config)

        configIns = config.Config()
        configIns.save()
        self.assertTrue(
            os.path.exists(
                os.path.join(os.path.expanduser("~"), ".autobrightness")))
Пример #2
0
    def test_each_backend(self):
        settings = config.Config()

        for backend in screen.Screen.getBackends():
            if backend == "powercfg":
                continue

            settings.backend = backend
            screenIns = screen.Screen(settings, gettext)

            if backend == "sysfs":
                interfaces = screenIns.backend.interfaces()
                if len(interfaces) < 1:
                    continue
                settings.setOption("sysfs", "interface", interfaces[0])

            currentBrightness = screenIns.getBrightness()
            self.assertGreaterEqual(currentBrightness, 0)

            if backend == "xrandr" and currentBrightness == 0:
                continue

            screenIns.setBrightness(screenIns.maxBrightness)
            self.assertEqual(screenIns.getBrightness(),
                             screenIns.maxBrightness)
Пример #3
0
 def test05_getOptin(self):
     configIns = config.Config(self.configfile)
     self.assertEqual(configIns.getOption("test", "value", int), 1)
     self.assertEqual(configIns.getOption("test", "valuestr"), "str")
     self.assertEqual(configIns.getOption("test", "valuestr", int), "str")
     self.assertIsNone(configIns.getOption("test", "None"))
     self.assertIsNone(configIns.getOption("test", "notexists"))
Пример #4
0
 def test_none(self):
     settings = config.Config()
     settings.backend = None
     screenIns = screen.Screen(settings, gettext)
     currentBrightness = screenIns.getBrightness()
     self.assertGreaterEqual(currentBrightness, 0)
     screenIns.setBrightness(0)
     screenIns.setBrightness(currentBrightness)
     screenIns.configSave()
Пример #5
0
    def test_backend(self):
        configIns = config.Config("test")
        self.createWindow(configIns)

        for i in range(self.view.backendCombo.count()):
            self.view.backendCombo.setCurrentIndex(i)
            QTest.mouseClick(self.view.saveButton, Qt.LeftButton)
        self.view.close()
        os.remove("test")
Пример #6
0
    def test_cameraButton(self):
        configIns = config.Config()
        configIns.camera = 0
        self.createWindow(configIns)
        QTimer.singleShot(1000, self.pressEnter)
        QTest.mouseClick(self.view.cameraButton, Qt.LeftButton)
        self.view.close()

        configIns.camera = "/dev/video0"
        self.createWindow(configIns)
        QTimer.singleShot(1000, self.pressEnter)
        QTest.mouseClick(self.view.cameraButton, Qt.LeftButton)
        self.view.close()
Пример #7
0
def main():
    parser = init_argparse()
    args = parser.parse_args()

    if args.config:
        # if config argument used create file
        settings = config.Config(args.config)
        settings.save()
    else:
        settings = config.Config()

    # select language
    if settings.language is None:
        lang = gettext
    else:
        lang = gettext.translation(
            "autobrightness", os.path.join(autobrightness.ROOT_DIR, 'locales'),
            [settings.language])
    global _
    _ = lang.gettext

    if args.start:
        sys.stdout = Unbuffered(sys.stdout)
        daemonIns = autobrightness.daemon.Daemon(settings, lang)
        daemonIns.start()
    elif args.set:
        brightnessIns = brightness.Brightness(settings, lang)
        brightnessIns.set(brightnessIns.calculate())
    else:
        app = QApplication([])
        app.setApplicationName("Auto Brightness")
        app.setApplicationDisplayName("Auto Brightness")
        app.setApplicationVersion(autobrightness.__version__)
        app.setQuitOnLastWindowClosed(False)
        trayIcon = autobrightness.gui.trayicon.TrayIcon(
            settings, autobrightness.gui.daemon.Service(), app, lang)
        trayIcon.show()
        app.exec_()
Пример #8
0
    def test_saveButton(self):
        configIns = config.Config("test")
        self.createWindow(configIns)

        # change settings on window
        self.comboChange(self.view.languageCombo)
        self.comboChange(self.view.backendCombo)
        self.view.cameraEdit.setText("1")
        self.view.intervalEdit.setValue(1)
        self.view.shortcutEdit.setText("F12")

        # click save and check config
        QTest.mouseClick(self.view.saveButton, Qt.LeftButton)
        configIns.load()
        self.checkConfig(configIns)
        self.view.close()
        os.remove("test")
Пример #9
0
    def test_calculate(self):
        settings = config.Config()
        settings.backend = None
        brightnessIns = brightness.Brightness(settings, gettext)
        self.assertGreater(brightnessIns.calculate(), 0)

        settings.gain = -100
        brightnessIns = brightness.Brightness(settings, gettext)
        self.assertGreater(brightnessIns.calculate(), 0)

        settings.gain = 100
        brightnessIns = brightness.Brightness(settings, gettext)
        self.assertLessEqual(brightnessIns.calculate(), 100)

        settings.camera = 999
        settings.gain = 0
        brightnessIns = brightness.Brightness(settings, gettext)
        self.assertGreater(brightnessIns.calculate(), 0)
Пример #10
0
 def test_set(self):
     settings = config.Config()
     settings.backend = None
     brightnessIns = brightness.Brightness(settings, gettext)
     brightnessIns.set(brightnessIns.calculate())
Пример #11
0
 def test_defaultConfig(self):
     self.createWindow(config.Config())
     self.checkConfig(config.Config())
     self.view.close()
Пример #12
0
 def test04_setOption(self):
     configIns = config.Config(self.configfile)
     configIns.setOption("test", "value", 1)
     configIns.setOption("test", "valuestr", "str")
     configIns.setOption("test", "None", None)
     configIns.save()
Пример #13
0
 def test03_saveload(self):
     configIns = config.Config(self.configfile)
     configIns.save()
     configIns.load()
     self.assertEqual(configIns.interval, 0)