def test_set_explicit_unicode(self):
        """Test setting an explicit unicode string (u + quotes)."""
        with current_app.app_context():
            config.set_("URL", u"u'http://тест.укр/'", self.cfg)

        with open(self._tmp) as f:
            self.assertRegexpMatches(f.read(), u"URL\s*=\s*u'http://\\\\u")
    def test_set_list_of_strings(self):
        """Test setting a list of string."""
        with current_app.app_context():
            config.set_("FOO", "['bar', 'biz']", self.cfg)

        with open(self._tmp) as f:
            self.assertRegexpMatches(f.read(), "FOO\s*=\s*\['bar',\s?'biz'\]")
    def test_set_true(self):
        """Test setting a True value."""
        with current_app.app_context():
            config.set_("SPAM", "True", self.cfg)

        with open(self._tmp) as f:
            self.assertRegexpMatches(f.read(), "SPAM\s*=\s*True")
    def test_set_false(self):
        """Test setting a False value."""
        with current_app.app_context():
            config.set_("EGGS", "False", self.cfg)

        with open(self._tmp) as f:
            self.assertRegexpMatches(f.read(), "EGGS\s*=\s*False")
    def test_set_list_of_strings(self):
        """Test setting a list of string."""
        with current_app.app_context():
            config.set_("FOO", "['bar', 'biz']", self.cfg)

        with open(self._tmp) as f:
            self.assertRegexpMatches(f.read(), "FOO\s*=\s*\['bar',\s?'biz'\]")
    def test_set_explicit_unicode(self):
        """Test setting an explicit unicode string (u + quotes)."""
        with current_app.app_context():
            config.set_("URL", u"u'http://тест.укр/'", self.cfg)

        with open(self._tmp) as f:
            self.assertRegexpMatches(f.read(), u"URL\s*=\s*u'http://\\\\u")
    def test_set_false(self):
        """Test setting a False value."""
        with current_app.app_context():
            config.set_("EGGS", "False", self.cfg)

        with open(self._tmp) as f:
            self.assertRegexpMatches(f.read(), "EGGS\s*=\s*False")
    def test_set_true(self):
        """Test setting a True value."""
        with current_app.app_context():
            config.set_("SPAM", "True", self.cfg)

        with open(self._tmp) as f:
            self.assertRegexpMatches(f.read(), "SPAM\s*=\s*True")
    def test_set_list_of_lists(self):
        """Test setting a list with sublists."""
        with current_app.app_context():
            config.set_("FOO", "['bar', 'biz', [1, 2, 3]]", self.cfg)

        with open(self._tmp) as f:
            self.assertRegexpMatches(f.read(),
                                     "FOO\s*=\s*\['bar', 'biz', \[1, 2, 3\]\]")
    def test_set_list_of_lists(self):
        """Test setting a list with sublists."""
        with current_app.app_context():
            config.set_("FOO", "['bar', 'biz', [1, 2, 3]]", self.cfg)

        with open(self._tmp) as f:
            self.assertRegexpMatches(f.read(),
                                     "FOO\s*=\s*\['bar', 'biz', \[1, 2, 3\]\]")
    def test_set_existing(self):
        """Test setting existing entry fails."""
        def exit(*args, **kwargs):
            pass
        _stdout = sys.stdout
        _exit = sys.exit
        sys.stdout = config.StringIO()
        sys.exit = exit

        with current_app.app_context():
            config.set_("DEBUG", "False", self.cfg)

        self.assertRegexpMatches(sys.stdout.getvalue(),
                                 "DEBUG is already filled")

        sys.exit = _exit
        sys.stdout = _stdout
    def test_set_existing(self):
        """Test setting existing entry fails."""
        def exit(*args, **kwargs):
            pass
        _stdout = sys.stdout
        _exit = sys.exit
        sys.stdout = config.StringIO()
        sys.exit = exit

        with current_app.app_context():
            config.set_("DEBUG", "False", self.cfg)

        self.assertRegexpMatches(sys.stdout.getvalue(),
                                 "DEBUG is already filled")

        sys.exit = _exit
        sys.stdout = _stdout