コード例 #1
0
 def test_from_invalid_json(self):
     # Invalid JSON
     with capture_output():
         jd = JSONObjectDict.from_json(JSONObject, '{"foo":{}')
         self.failIf(jd)
         # Valid but unexpected Command field
         self.failIf(JSONObjectDict.from_json(JSONObject, '{"bar":{"name":"bar", "invalid":"foo"}'))
コード例 #2
0
 def test_from_invalid_json(self):
     # Invalid JSON
     with capture_output():
         jd = JSONObjectDict.from_json(JSONObject, '{"foo":{}')
         self.failIf(jd)
         # Valid but unexpected Command field
         self.failIf(JSONObjectDict.from_json(JSONObject,
             '{"bar":{"name":"bar", "invalid":"foo"}'))
コード例 #3
0
 def setUp(self):
     module = self.modules["CustomCommands"]
     globals().update(vars(module))
     self.plugin = self.plugins["CustomCommands"].cls
     config.init()
     self.cmd_list = CustomCommands.DEFAULT_COMS
     self.commands = JSONObjectDict.from_list(self.cmd_list)
コード例 #4
0
 def setUp(self):
     module = self.modules["CustomCommands"]
     globals().update(vars(module))
     self.plugin = self.plugins["CustomCommands"].cls
     config.init()
     self.cmd_list = CustomCommands.DEFAULT_COMS
     self.commands = JSONObjectDict.from_list(self.cmd_list)
コード例 #5
0
 def test_from_list(self):
     baz_man = JSONObject("baz man!")
     lst = [JSONObject("foo"), JSONObject("bar"), baz_man]
     data = JSONObjectDict.from_list(lst)
     self.failUnlessEqual(len(data), len(lst))
     self.failUnless("baz man!" in data)
     self.failUnlessEqual(baz_man, data["baz man!"])
コード例 #6
0
 def test_from_list(self):
     baz_man = JSONObject("baz man!")
     lst = [JSONObject("foo"), JSONObject("bar"), baz_man]
     data = JSONObjectDict.from_list(lst)
     self.failUnlessEqual(len(data), len(lst))
     self.failUnless("baz man!" in data)
     self.failUnlessEqual(baz_man, data["baz man!"])
コード例 #7
0
    def test_save_all(self):
        data = JSONObjectDict.from_json(self.WibbleData, self.WIBBLE_JSON_STR)
        fd, filename = mkstemp(suffix=".json")
        os.close(fd)
        try:
            ret = data.save(filename)
            with open(filename, "rb") as f:
                jstr = f.read()
            # Check we also return the string as documented...
            self.failUnlessEqual(jstr, ret)
        finally:
            os.unlink(filename)

        # Check we have the right number of items
        self.failUnlessEqual(len(json.loads(jstr)), len(data))

        # Check them one by one (for convenience of debugging)
        parsed = JSONObjectDict.from_json(self.WibbleData, jstr)
        for o in data.values():
            self.failUnlessEqual(parsed[o.name], o)
コード例 #8
0
    def test_save_all(self):
        data = JSONObjectDict.from_json(self.WibbleData, self.WIBBLE_JSON_STR)
        fd, filename = mkstemp(suffix=".json")
        os.close(fd)
        try:
            ret = data.save(filename)
            with open(filename, "rb") as f:
                jstr = f.read()
            # Check we also return the string as documented...
            self.failUnlessEqual(jstr, ret)
        finally:
            os.unlink(filename)

        # Check we have the right number of items
        self.failUnlessEqual(len(json.loads(jstr)), len(data))

        # Check them one by one (for convenience of debugging)
        parsed = JSONObjectDict.from_json(self.WibbleData, jstr)
        for o in data.values():
            self.failUnlessEqual(parsed[o.name], o)
コード例 #9
0
    def _get_saved_commands(cls):
        filename = cls.COMS_FILE
        print_d("Loading saved commands from '%s'..." % filename)
        coms = None
        try:
            with open(filename, "r", encoding="utf-8") as f:
                coms = JSONObjectDict.from_json(Command, f.read())
        except (IOError, ValueError) as e:
            print_w("Couldn't parse saved commands (%s)" % e)

        # Failing all else...
        if not coms:
            print_d("No commands found in %s. Using defaults." % filename)
            coms = {c.name: c for c in cls.DEFAULT_COMS}
        print_d("Loaded commands: %s" % coms.keys())
        return coms
コード例 #10
0
ファイル: custom_commands.py プロジェクト: LudoBike/quodlibet
    def _get_saved_commands(cls):
        filename = cls.COMS_FILE
        print_d("Loading saved commands from '%s'..." % filename)
        coms = None
        try:
            with open(filename, "r", encoding="utf-8") as f:
                coms = JSONObjectDict.from_json(Command, f.read())
        except (IOError, ValueError) as e:
            print_w("Couldn't parse saved commands (%s)" % e)

        # Failing all else...
        if not coms:
            print_d("No commands found in %s. Using defaults." % filename)
            coms = {c.name: c for c in cls.DEFAULT_COMS}
        print_d("Loaded commands: %s" % coms.keys())
        return coms
コード例 #11
0
    def _get_saved_searches(cls):
        filename = cls.COMS_FILE
        print_d("Loading saved commands from '%s'..." % filename)
        coms = None
        try:
            with open(filename) as f:
                coms = JSONObjectDict.from_json(Command, f.read())
        except IOError:
            pass
        except ValueError as e:
            print_w("Couldn't parse saved commands (%s)" % e)

        # Failing all else...
        if not coms:
            print_d("No commands found in %s. Using defaults." % filename)
            coms = dict([(c.name, c) for c in cls.DEFAULT_COMS])
        print_d("Loaded commands: %s" % coms.keys())
        return coms
コード例 #12
0
    def _get_saved_searches(cls):
        filename = cls.COMS_FILE
        print_d("Loading saved commands from '%s'..." % filename)
        coms = None
        try:
            with open(filename) as f:
                coms = JSONObjectDict.from_json(Command, f.read())
        except IOError:
            pass
        except ValueError as e:
            print_w("Couldn't parse saved commands (%s)" % e)

        # Failing all else...
        if not coms:
            print_d("No commands found in %s. Using defaults." % filename)
            coms = dict([(c.name, c) for c in cls.DEFAULT_COMS])
        print_d("Loaded commands: %s" % coms.keys())
        return coms
コード例 #13
0
 def test_subclass_from_json(self):
     coms = JSONObjectDict.from_json(self.WibbleData, self.WIBBLE_JSON_STR)
     self.failUnlessEqual(len(coms), 2)
     self.failUnlessEqual(coms['foo'].__class__, self.WibbleData)
コード例 #14
0
 def __finish(self, widget):
     # TODO: Warn about impending deletion of nameless items, or something
     all = JSONObjectDict.from_list(
         [row[0] for row in self.model if row[0].name])
     all.save(filename=self.filename)
コード例 #15
0
ファイル: data_editors.py プロジェクト: urielz/quodlibet
 def __finish(self, widget):
     # TODO: Warn about impending deletion of nameless items, or something
     all = JSONObjectDict.from_list(
             [row[0] for row in self.model if row[0].name])
     all.save(filename=self.filename)
コード例 #16
0
 def setUp(self):
     globals().update(vars(self.modules["CustomCommands"]))
     config.init()
     self.cmd_list = CustomCommands.DEFAULT_COMS
     self.commands = JSONObjectDict.from_list(self.cmd_list)
コード例 #17
0
 def setUp(self):
     globals().update(vars(self.modules["CustomCommands"]))
     config.init()
     self.cmd_list = CustomCommands.DEFAULT_COMS
     self.commands = JSONObjectDict.from_list(self.cmd_list)
コード例 #18
0
 def test_subclass_from_json(self):
     coms = JSONObjectDict.from_json(self.WibbleData, self.WIBBLE_JSON_STR)
     self.failUnlessEqual(len(coms), 2)
     self.failUnlessEqual(coms['foo'].__class__, self.WibbleData)