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)
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)
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)
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)
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)
def test_comment_after_section(self): cf = self.from_file(b"[section] # foo\n") self.assertEqual(ConfigFile({(b"section", ): {}}), cf)
def test_comment_before_section(self): cf = self.from_file(b"# foo\n[section]\n") self.assertEqual(ConfigFile({(b"section", ): {}}), cf)
def test_empty_line_before_section(self): cf = self.from_file(b"\n[section]\n") self.assertEqual(ConfigFile({(b"section", ): {}}), cf)
def test_from_file_empty(self): cf = self.from_file(b"") self.assertEqual(ConfigFile(), cf)
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())
def test_empty(self): ConfigFile()
def from_file(self, text): return ConfigFile.from_file(BytesIO(text))
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())
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())
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)
def test_eq(self): self.assertEqual(ConfigFile(), ConfigFile())
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)
def test_write_to_file_empty(self): c = ConfigFile() f = BytesIO() c.write_to_file(f) self.assertEqual(b"", f.getvalue())