Exemplo n.º 1
0
 def setUp(self):
     quodlibet.config.init()
     h, self.fname = mkstemp()
     os.close(h)
     with open(self.fname + ".saved", "w") as f:
         f.write("%s\n%s\n" %
                 (self.TEST_KV_DATA[0][1], self.TEST_KV_DATA[0][0]))
     self.sae = StandaloneEditor(self.fname, "test", None, None)
Exemplo n.º 2
0
 def test_defaults(self):
     defaults = [("Dot-com Dream", "http://<artist>.com")]
     try:
         os.unlink(self.fname)
     except OSError:
         pass
     # Now create a new SAE without saved results and use defaults
     self.fname = "foo"
     self.sae.destroy()
     self.sae = StandaloneEditor(self.fname, "test2", defaults, None)
     self.sae.write()
     data = [(row[1], row[0]) for row in self.sae.model]
     self.failUnlessEqual(defaults, data)
Exemplo n.º 3
0
    def edit_patterns(cls, button):
        def valid_uri(s):
            # TODO: some pattern validation too (that isn't slow)
            try:
                p = Pattern(s)
                return (p and uri_is_valid(s))
            except ValueError:
                return False

        win = StandaloneEditor(filename=cls.PATTERNS_FILE,
                               title=_("Search URL patterns"),
                               initial=cls.DEFAULT_URL_PATS,
                               validator=valid_uri)
        win.show()
Exemplo n.º 4
0
    def edit_patterns(cls, button):
        def valid_uri(s):
            # TODO: some pattern validation too (that isn't slow)
            try:
                p = Pattern(s)
                return (p and uri_is_valid(s))
            except ValueError:
                return False

        win = StandaloneEditor(filename=cls.PATTERNS_FILE,
                               title=_("Search URL patterns"),
                               initial=cls.DEFAULT_URL_PATS,
                               validator=valid_uri)
        win.show()
Exemplo n.º 5
0
 def setUp(self):
     quodlibet.config.init()
     self.fname = tempfile.mkstemp()[1]
     f = file(self.fname + ".saved", "w")
     f.write("%s\n%s\n" % (self.TEST_KV_DATA[0][1], self.TEST_KV_DATA[0][0]))
     f.close()
     self.sae = StandaloneEditor(self.fname, "test", None, None)
Exemplo n.º 6
0
 def setUp(self):
     quodlibet.config.init()
     h, self.fname = mkstemp()
     os.close(h)
     with open(self.fname + ".saved", "w") as f:
         f.write("%s\n%s\n" % (self.TEST_KV_DATA[0][1], self.TEST_KV_DATA[0][0]))
     self.sae = StandaloneEditor(self.fname, "test", None, None)
Exemplo n.º 7
0
 def _get_saved_searches(self):
     filename = self.PATTERNS_FILE + ".saved"
     self._url_pats = StandaloneEditor.load_values(filename)
     # Failing all else...
     if not len(self._url_pats):
         print_d("No saved searches found in %s. Using defaults." %
                 filename)
         self._url_pats = self.DEFAULT_URL_PATS
Exemplo n.º 8
0
 def _get_saved_searches(self):
     filename = self.PATTERNS_FILE + ".saved"
     self._url_pats = StandaloneEditor.load_values(filename)
     # Failing all else...
     if not len(self._url_pats):
         print_d("No saved searches found in %s. Using defaults." %
                 filename)
         self._url_pats = self.DEFAULT_URL_PATS
Exemplo n.º 9
0
 def test_defaults(self):
     defaults = [("Dot-com Dream", "http://<artist>.com")]
     try:
         os.unlink(self.fname)
     except OSError:
         pass
     # Now create a new SAE without saved results and use defaults
     self.fname = "foo"
     self.sae.destroy()
     self.sae = StandaloneEditor(self.fname, "test2", defaults, None)
     self.sae.write()
     data = [(row[1], row[0]) for row in self.sae.model]
     self.failUnlessEqual(defaults, data)
Exemplo n.º 10
0
class TStandaloneEditor(TestCase):
    TEST_KV_DATA = [
        ("Search Foo", "https://foo.com/search?q=<artist>-<title>")]

    def setUp(self):
        quodlibet.config.init()
        h, self.fname = mkstemp()
        os.close(h)
        with open(self.fname + ".saved", "w") as f:
            f.write(
                "%s\n%s\n" % (self.TEST_KV_DATA[0][1],
                              self.TEST_KV_DATA[0][0]))
        self.sae = StandaloneEditor(self.fname, "test", None, None)

    def test_constructor(self):
        self.failUnless(self.sae.model)
        data = [(row[1], row[0]) for row in self.sae.model]
        self.failUnlessEqual(data, self.TEST_KV_DATA)

    def test_load_values(self):
        values = StandaloneEditor.load_values(self.fname + ".saved")
        self.failUnlessEqual(self.TEST_KV_DATA, values)

    def test_defaults(self):
        defaults = [("Dot-com Dream", "http://<artist>.com")]
        try:
            os.unlink(self.fname)
        except OSError:
            pass
        # Now create a new SAE without saved results and use defaults
        self.fname = "foo"
        self.sae.destroy()
        self.sae = StandaloneEditor(self.fname, "test2", defaults, None)
        self.sae.write()
        data = [(row[1], row[0]) for row in self.sae.model]
        self.failUnlessEqual(defaults, data)

    def tearDown(self):
        self.sae.destroy()
        try:
            os.unlink(self.fname)
            os.unlink(self.fname + ".saved")
        except OSError:
            pass
        quodlibet.config.quit()
Exemplo n.º 11
0
class TStandaloneEditor(TestCase):
    TEST_KV_DATA = [("Search Foo", "https://foo.com/search?q=<artist>-<title>")
                    ]

    def setUp(self):
        quodlibet.config.init()
        h, self.fname = mkstemp()
        os.close(h)
        f = file(self.fname + ".saved", "w")
        f.write("%s\n%s\n" %
                (self.TEST_KV_DATA[0][1], self.TEST_KV_DATA[0][0]))
        f.close()
        self.sae = StandaloneEditor(self.fname, "test", None, None)

    def test_constructor(self):
        self.failUnless(self.sae.model)
        data = [(row[1], row[0]) for row in self.sae.model]
        self.failUnlessEqual(data, self.TEST_KV_DATA)

    def test_load_values(self):
        values = StandaloneEditor.load_values(self.fname + ".saved")
        self.failUnlessEqual(self.TEST_KV_DATA, values)

    def test_defaults(self):
        defaults = [("Dot-com Dream", "http://<artist>.com")]
        try:
            os.unlink(self.fname)
        except OSError:
            pass
        # Now create a new SAE without saved results and use defaults
        self.fname = "foo"
        self.sae.destroy()
        self.sae = StandaloneEditor(self.fname, "test2", defaults, None)
        self.sae.write()
        data = [(row[1], row[0]) for row in self.sae.model]
        self.failUnlessEqual(defaults, data)

    def tearDown(self):
        self.sae.destroy()
        try:
            os.unlink(self.fname)
            os.unlink(self.fname + ".saved")
        except OSError:
            pass
        quodlibet.config.quit()
Exemplo n.º 12
0
 def test_load_values(self):
     values = StandaloneEditor.load_values(self.fname + ".saved")
     self.failUnlessEqual(self.TEST_KV_DATA, values)
Exemplo n.º 13
0
 def test_load_values(self):
     values = StandaloneEditor.load_values(self.fname + ".saved")
     self.failUnlessEqual(self.TEST_KV_DATA, values)