示例#1
0
    def __init__(self, **kwargs):
        self.path = kwargs.get('path', None)
        self.file = kwargs.get('file', None)

        if self.path:
            if os.path.exists(self.path):

                config_path = self.detect_git_config(self.path)
                if os.path.exists(config_path):
                    self.config_path = config_path
                    self.config = ConfigFile.from_path(config_path)
                else:
                    raise GitRepoNotFoundError(self.path)
            else:
                raise IOError(self.path)

        else:
            self.config = ConfigFile.from_file(self.file)
示例#2
0
    def __init__(self,**kwargs):
        self.path = kwargs.get('path', None)
        self.file = kwargs.get('file', None)

        if self.path:
            if os.path.exists(self.path):

                config_path = self.detect_git_config(self.path)
                if os.path.exists(config_path):
                    self.config_path = config_path
                    self.config = ConfigFile.from_path(config_path)
                else:
                    raise GitRepoNotFoundError(self.path)
            else:
                raise IOError(self.path)

        else:
            self.config = ConfigFile.from_file(self.file)
示例#3
0
    def test_default_config(self):
        cf = self.from_file("""[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
""")
        self.assertEqual(
            ConfigFile({
                ("core", ): {
                    "repositoryformatversion": "0",
                    "filemode": "true",
                    "bare": "false",
                    "logallrefupdates": "true"
                }
            }), cf)
示例#4
0
 def test_comment_after_variable(self):
     cf = self.from_file("[section]\nbar= foo # a comment\n")
     self.assertEqual(ConfigFile({("section", ): {"bar": "foo"}}), cf)
示例#5
0
 def test_comment_after_section(self):
     cf = self.from_file("[section] # foo\n")
     self.assertEqual(ConfigFile({("section", ): {}}), cf)
示例#6
0
 def test_comment_before_section(self):
     cf = self.from_file("# foo\n[section]\n")
     self.assertEqual(ConfigFile({("section", ): {}}), cf)
示例#7
0
 def test_empty_line_before_section(self):
     cf = self.from_file("\n[section]\n")
     self.assertEqual(ConfigFile({("section", ): {}}), cf)
示例#8
0
 def test_from_file_empty(self):
     cf = self.from_file("")
     self.assertEqual(ConfigFile(), cf)
示例#9
0
 def test_eq(self):
     self.assertEqual(ConfigFile(), ConfigFile())
示例#10
0
 def test_empty(self):
     ConfigFile()
示例#11
0
 def from_file(self, text):
     # text = bytes(text, 'UTF-8')
     text = text.encode("utf-8")
     return ConfigFile.from_file(BytesIO(text))
示例#12
0
 def test_write_to_file_subsection(self):
     c = ConfigFile()
     c.set(("branch", "blie"), "foo", "bar")
     f = BytesIO()
     c.write_to_file(f)
     self.assertEqual(b"[branch \"blie\"]\n\tfoo = bar\n", f.getvalue())
示例#13
0
 def test_write_to_file_section(self):
     c = ConfigFile()
     c.set(("core", ), "foo", "bar")
     f = BytesIO()
     c.write_to_file(f)
     self.assertEqual(b"[core]\n\tfoo = bar\n", f.getvalue())
示例#14
0
 def test_write_to_file_empty(self):
     c = ConfigFile()
     f = BytesIO()
     c.write_to_file(f)
     self.assertEqual(b"", f.getvalue())