Example #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)
Example #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)
Example #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)
Example #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)
Example #5
0
 def test_comment_after_section(self):
     cf = self.from_file("[section] # foo\n")
     self.assertEqual(ConfigFile({("section", ): {}}), cf)
Example #6
0
 def test_comment_before_section(self):
     cf = self.from_file("# foo\n[section]\n")
     self.assertEqual(ConfigFile({("section", ): {}}), cf)
Example #7
0
 def test_empty_line_before_section(self):
     cf = self.from_file("\n[section]\n")
     self.assertEqual(ConfigFile({("section", ): {}}), cf)
Example #8
0
 def test_from_file_empty(self):
     cf = self.from_file("")
     self.assertEqual(ConfigFile(), cf)
Example #9
0
 def test_eq(self):
     self.assertEqual(ConfigFile(), ConfigFile())
Example #10
0
 def test_empty(self):
     ConfigFile()
Example #11
0
 def from_file(self, text):
     # text = bytes(text, 'UTF-8')
     text = text.encode("utf-8")
     return ConfigFile.from_file(BytesIO(text))
Example #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())
Example #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())
Example #14
0
 def test_write_to_file_empty(self):
     c = ConfigFile()
     f = BytesIO()
     c.write_to_file(f)
     self.assertEqual(b"", f.getvalue())