Example #1
0
    def test_quoted(self):
        cf = self.from_file(b"""[gui]
\tfontdiff = -family \\\"Ubuntu Mono\\\" -size 11 -overstrike 0
""")
        self.assertEqual(
            ConfigFile({
                (b'gui', ): {
                    b'fontdiff':
                    b'-family "Ubuntu Mono" -size 11 -overstrike 0',
                }
            }), cf)
Example #2
0
    def testSubmodules(self):
        cf = ConfigFile.from_file(
            BytesIO(b"""\
[submodule "core/lib"]
\tpath = core/lib
\turl = https://github.com/phhusson/QuasselC.git
"""))
        got = list(parse_submodules(cf))
        self.assertEqual(
            [(b'core/lib', b'https://github.com/phhusson/QuasselC.git',
              b'core/lib')], got)
Example #3
0
    def test_quoted_multiline(self):
        cf = self.from_file(b"""[alias]
who = \"!who() {\\
  git log --no-merges --pretty=format:'%an - %ae' $@ | uniq -c | sort -rn;\\
};\\
who\"
""")
        self.assertEqual(
            ConfigFile({
                (b'alias', ): {
                    b'who':
                    (b"!who() {git log --no-merges --pretty=format:'%an - "
                     b"%ae' $@ | uniq -c | sort -rn;};who")
                }
            }), cf)
Example #4
0
    def test_default_config(self):
        cf = self.from_file(b"""[core]
\trepositoryformatversion = 0
\tfilemode = true
\tbare = false
\tlogallrefupdates = true
""")
        self.assertEqual(
            ConfigFile({
                (b"core", ): {
                    b"repositoryformatversion": b"0",
                    b"filemode": b"true",
                    b"bare": b"false",
                    b"logallrefupdates": b"true"
                }
            }), cf)
Example #5
0
 def test_comment_after_variable(self):
     cf = self.from_file(b"[section]\nbar= foo # a comment\n")
     self.assertEqual(ConfigFile({(b"section", ): {b"bar": b"foo"}}), cf)
Example #6
0
 def test_comment_after_section(self):
     cf = self.from_file(b"[section] # foo\n")
     self.assertEqual(ConfigFile({(b"section", ): {}}), cf)
Example #7
0
 def test_comment_before_section(self):
     cf = self.from_file(b"# foo\n[section]\n")
     self.assertEqual(ConfigFile({(b"section", ): {}}), cf)
Example #8
0
 def test_empty_line_before_section(self):
     cf = self.from_file(b"\n[section]\n")
     self.assertEqual(ConfigFile({(b"section", ): {}}), cf)
Example #9
0
 def test_from_file_empty(self):
     cf = self.from_file(b"")
     self.assertEqual(ConfigFile(), cf)
Example #10
0
 def test_write_to_file_section(self):
     c = ConfigFile()
     c.set((b"core", ), b"foo", b"bar")
     f = BytesIO()
     c.write_to_file(f)
     self.assertEqual(b"[core]\n\tfoo = bar\n", f.getvalue())
Example #11
0
 def test_empty(self):
     ConfigFile()
Example #12
0
 def from_file(self, text):
     return ConfigFile.from_file(BytesIO(text))
Example #13
0
 def test_set_hash_gets_quoted(self):
     c = ConfigFile()
     c.set(b"xandikos", b"color", b"#665544")
     f = BytesIO()
     c.write_to_file(f)
     self.assertEqual(b"[xandikos]\n\tcolor = \"#665544\"\n", f.getvalue())
Example #14
0
 def test_write_to_file_subsection(self):
     c = ConfigFile()
     c.set((b"branch", b"blie"), b"foo", b"bar")
     f = BytesIO()
     c.write_to_file(f)
     self.assertEqual(b"[branch \"blie\"]\n\tfoo = bar\n", f.getvalue())
Example #15
0
 def test_comment_character_within_value_string(self):
     cf = self.from_file(b"[section]\nbar= \"foo#bar\"\n")
     self.assertEqual(ConfigFile({(b"section", ): {
                                      b"bar": b"foo#bar"
                                  }}), cf)
Example #16
0
 def test_eq(self):
     self.assertEqual(ConfigFile(), ConfigFile())
Example #17
0
 def test_comment_character_within_section_string(self):
     cf = self.from_file(b"[branch \"foo#bar\"] # a comment\nbar= foo\n")
     self.assertEqual(
         ConfigFile({(b"branch", b"foo#bar"): {
                         b"bar": b"foo"
                     }}), cf)
Example #18
0
 def test_write_to_file_empty(self):
     c = ConfigFile()
     f = BytesIO()
     c.write_to_file(f)
     self.assertEqual(b"", f.getvalue())