Ejemplo n.º 1
0
    def test_versioning(self):
        with temp_filename() as filename:
            conf = Config(version=41)
            conf.add_section("foo")
            conf.set("foo", "bar", "quux")
            conf.write(filename)
            self.assertRaises(Error, conf.get_version)

            # old was 41, we have 42, so upgrade
            def func(config, old, new):
                if old < 42:
                    config.set("foo", "bar", "nope")
            conf = Config(version=42)
            conf.register_upgrade_function(func)
            conf.read(filename)
            self.assertEqual(conf.get_version(), 41)
            self.assertEqual(conf.get("foo", "bar"), "nope")

            # write doesn't change version
            conf.write(filename)
            self.assertEqual(conf.get_version(), 41)

            # but if we load again, it does
            conf.read(filename)
            self.assertEqual(conf.get_version(), 42)
Ejemplo n.º 2
0
    def test_versioning(self):
        with temp_filename() as filename:
            conf = Config(version=41)
            conf.add_section("foo")
            conf.set("foo", "bar", "quux")
            conf.write(filename)
            self.assertRaises(Error, conf.get_version)

            # old was 41, we have 42, so upgrade
            def func(config, old, new):
                if old < 42:
                    config.set("foo", "bar", "nope")

            conf = Config(version=42)
            conf.register_upgrade_function(func)
            conf.read(filename)
            self.assertEqual(conf.get_version(), 41)
            self.assertEqual(conf.get("foo", "bar"), "nope")

            # write doesn't change version
            conf.write(filename)
            self.assertEqual(conf.get_version(), 41)

            # but if we load again, it does
            conf.read(filename)
            self.assertEqual(conf.get_version(), 42)
Ejemplo n.º 3
0
 def test_versioning_disabled(self):
     # we don't pass a version, so versioning is disabled
     conf = Config()
     self.assertRaises(Error, conf.get_version)
     with temp_filename() as filename:
         conf.read(filename)
     self.assertRaises(Error, conf.register_upgrade_function, lambda: None)
Ejemplo n.º 4
0
 def test_versioning_disabled(self):
     # we don't pass a version, so versioning is disabled
     conf = Config()
     self.assertRaises(Error, conf.get_version)
     with temp_filename() as filename:
         conf.read(filename)
     self.assertRaises(Error, conf.register_upgrade_function, lambda: None)
Ejemplo n.º 5
0
    def test_load_items(self):
        from quodlibet.library.libraries import load_items

        with temp_filename() as filename:
            with open(filename, "wb") as h:
                h.write(self.PICKLE)

            self.assertEqual(len(load_items(filename)), len(formats.types))
Ejemplo n.º 6
0
 def test_response(self):
     with temp_filename() as fn:
         mock = Mock(resp=b"resp")
         remote = QuodLibetUnixRemote(None, mock)
         remote._callback(b"\x00foo\x00%s\x00" % fn)
         self.assertEqual(mock.lines, [b"foo"])
         with open(fn, "rb") as h:
             self.assertEqual(h.read(), b"resp")
Ejemplo n.º 7
0
 def test_response(self):
     with temp_filename() as fn:
         mock = Mock(resp=b"resp")
         remote = QuodLibetUnixRemote(None, mock)
         remote._callback(b"\x00foo\x00%s\x00" % fn)
         self.assertEqual(mock.lines, [b"foo"])
         with open(fn, "rb") as h:
             self.assertEqual(h.read(), b"resp")
Ejemplo n.º 8
0
    def test_dump_items(self):
        from quodlibet.library.libraries import dump_items, load_items

        types = formats.types
        instances = []
        for t in types:
            instances.append(AudioFile.__new__(t))

        with temp_filename() as filename:
            dump_items(filename, instances)
            self.assertEqual(len(load_items(filename)), len(formats.types))
Ejemplo n.º 9
0
    def test_upgrade_first_read(self):
        # don't run upgrade funcs if there is no config file yet
        with temp_filename() as filename:
            pass

        conf = Config(version=41)

        def func(*args):
            self.assertTrue(False)
        conf.register_upgrade_function(func)
        conf.read(filename)
Ejemplo n.º 10
0
    def test_pickle(self):
        types = formats.types
        instances = []
        for t in types:
            instances.append(AudioFile.__new__(t))

        with temp_filename() as filename:
            with open(filename, "wb") as h:
                pickle.dump(instances, h, 1)

            with open(filename, "rb") as h:
                self.assertEqual(len(pickle.load(h)), len(formats.types))
Ejemplo n.º 11
0
    def test_upgrade_first_read(self):
        # don't run upgrade funcs if there is no config file yet
        with temp_filename() as filename:
            pass

        conf = Config(version=41)

        def func(*args):
            self.assertTrue(False)

        conf.register_upgrade_function(func)
        conf.read(filename)
Ejemplo n.º 12
0
    def test_versioning_upgrade_func(self):
        called = []

        with temp_filename() as filename:
            conf = Config(version=0)

            def func(*args):
                called.append(args)

            conf.register_upgrade_function(func)
            self.assertRaises(Error, conf.get_version)
            conf.read(filename)
            self.assertEqual(conf.get_version(), -1)
            conf.register_upgrade_function(func)

        self.assertEqual([(conf, -1, 0), (conf, -1, 0)], called)
Ejemplo n.º 13
0
    def test_versioning_upgrade_func(self):
        called = []

        with temp_filename() as filename:
            conf = Config(version=0)

            def func(*args):
                called.append(args)

            conf.register_upgrade_function(func)
            self.assertRaises(Error, conf.get_version)
            conf.read(filename)
            self.assertEqual(conf.get_version(), -1)
            conf.register_upgrade_function(func)

        self.assertEqual([(conf, -1, 0), (conf, -1, 0)], called)