Exemple #1
0
    def test_save_json_conf(self):
        tmp = TempDir()
        name = random_id() + '.json'
        f = tmp.join(name)

        # No pre-existing file:
        key = random_id()
        value = random_id()
        conf = {'foo': 'bar', key: value}
        self.assertIsNone(daemon.save_json_conf(f, conf))
        self.assertEqual(json.load(open(f, 'r')), {'foo': 'bar', key: value})
        self.assertEqual(os.listdir(tmp.dir), [name])

        # Pre-existing file:
        key = random_id()
        value = random_id()
        conf = {'bar': 'baz', key: value}
        self.assertIsNone(daemon.save_json_conf(f, conf))
        self.assertEqual(json.load(open(f, 'r')), {'bar': 'baz', key: value})
        self.assertEqual(os.listdir(tmp.dir), [name])

        # Empty conf:
        self.assertIsNone(daemon.save_json_conf(f, {}))
        self.assertEqual(json.load(open(f, 'r')), {})
        self.assertEqual(os.listdir(tmp.dir), [name])
Exemple #2
0
    def test_load_json_conf(self):
        tmp = TempDir()
        f = tmp.join('system76-daemon.json')

        # Missing file:
        self.assertEqual(daemon.load_json_conf(f), {})

        # Invalid JSON:
        open(f, 'x').write('invalid json')
        self.assertEqual(daemon.load_json_conf(f), {})

        # JSON does not contain a dict:
        open(f, 'w').write(json.dumps(['hello', 'world']))
        self.assertEqual(daemon.load_json_conf(f), {})

        # dict is empty:
        open(f, 'w').write(json.dumps({}))
        self.assertEqual(daemon.load_json_conf(f), {})

        # dict has stuffs:
        open(f, 'w').write(json.dumps({'foo': 'bar'}))
        self.assertEqual(daemon.load_json_conf(f), {'foo': 'bar'})

        # dict has random_stuffs:
        key = random_id()
        value = random_id()
        open(f, 'w').write(json.dumps({key: value}))
        self.assertEqual(daemon.load_json_conf(f), {key: value})
Exemple #3
0
    def test_init(self):
        args = DummyArgs('/home/oem', False)
        product = {
            'name': 'Gazelle Professional',
            'drivers': [],
            'prefs': [],
        }
        ui = gtk.UI('gazp9', product, args)
        self.assertIsNone(ui.thread)
        self.assertEqual(ui.model, 'gazp9')
        self.assertIs(ui.product, product)
        self.assertIs(ui.args, args)
        self.assertIsInstance(ui.builder, Gtk.Builder)
        self.assertIsInstance(ui.window, Gtk.Window)
        self.assertEqual(
            ui.builder.get_object('sysName').get_text(),
            'Gazelle Professional'
        )
        self.assertEqual(
            ui.builder.get_object('sysModel').get_text(),
            'gazp9'
        )
        self.assertEqual(
            ui.builder.get_object('ubuntuVersion').get_text(),
            '{} {} ({})'.format(*distro.linux_distribution())
        )
        self.assertEqual(
            ui.builder.get_object('driverVersion').get_text(),
            system76driver.__version__
        )

        model = random_id()
        name = random_id()
        product = {'name': name}
        ui = gtk.UI(model, product, args)
        self.assertIsNone(ui.thread)
        self.assertEqual(ui.model, model)
        self.assertIs(ui.product, product)
        self.assertEqual(ui.product, {'name': name})
        self.assertIs(ui.args, args)
        self.assertIsInstance(ui.builder, Gtk.Builder)
        self.assertIsInstance(ui.window, Gtk.Window)
        self.assertEqual(ui.builder.get_object('sysName').get_text(), name)
        self.assertEqual(ui.builder.get_object('sysModel').get_text(), model)
        self.assertEqual(
            ui.builder.get_object('ubuntuVersion').get_text(),
            '{} {} ({})'.format(*distro.linux_distribution())
        )
        self.assertEqual(
            ui.builder.get_object('driverVersion').get_text(),
            system76driver.__version__
        )
Exemple #4
0
 def test_set_notify(self):
     args = DummyArgs('/home/oem', False)
     ui = gtk.UI('gazp9', {'name': 'Gazelle Professional'}, args)
     text = random_id()
     self.assertIsNone(ui.set_notify('gtk-execute', text))
     self.assertEqual(ui.notify_text.get_text(), text)