def make_tracker(self, direc=None, name=None): ''' Make a tracker in the current directory with the given or a randomly generated name. This is called automatically on init. It is left public for scenarios where having multiple trackers is desired. ''' if name is not None: path = name else: path = get_uuid() if direc is not None: path = os.path.join(direc, path) return Tracker.new(path)
def __init__(self, path=None): # set config file fields self.fields = { 'user': { 'name': None, 'email': None }, 'core': { 'editor': 'vim', 'autocommit': True, 'color': True }, 'web': { # This generated key is overridden if it exists # in the config file already. It is required for the # Flask app. 'secret_key': get_uuid() } } # set field types (so they're parsed correctly). # default type is string, so most don't need to be set. # see the ConfigFile class for more info. self.types = {'core': {'autocommit': bool, 'color': bool}} if path is None: HOME = os.getenv('HOME') hprconfig = os.path.join(HOME, '.hprconfig') if os.path.exists(hprconfig): path = hprconfig self.path = path if self.path is not None and os.path.exists(self.path): self.from_file(path, self.types) super(BaseFile, self).__init__() # We really need a name and email, so we'll try # and steal them from $HOME/.gitconfig if they are # there but missing here. gitconfig = parse_gitconfig() if gitconfig: if self.user['name'] is None: try: self.user['name'] = gitconfig['user']['name'] except KeyError: pass if self.user['email'] is None: try: self.user['email'] = gitconfig['user']['email'] except KeyError: pass
def test_issue(self): t = Tracker.new(self.path) i1 = Issue(t) i1.save() i2 = t.issue(i1.id) # verify that issue() returns an Issue assert type(i2) is Issue # verify that the issues match assert i1.fields == i2.fields # invalid SHAs should raise BadReference invalid_sha = get_uuid() try: t.issue(invalid_sha) except BadReference: pass
def __init__(self, path=None): # set config file fields self.fields = { "user": {"name": None, "email": None}, "core": {"editor": "vim", "autocommit": True, "color": True}, "web": { # This generated key is overridden if it exists # in the config file already. It is required for the # Flask app. "secret_key": get_uuid() }, } # set field types (so they're parsed correctly). # default type is string, so most don't need to be set. # see the ConfigFile class for more info. self.types = {"core": {"autocommit": bool, "color": bool}} if path is None: HOME = os.getenv("HOME") hprconfig = os.path.join(HOME, ".hprconfig") if os.path.exists(hprconfig): path = hprconfig self.path = path if self.path is not None and os.path.exists(self.path): self.from_file(path, self.types) super(BaseFile, self).__init__() # We really need a name and email, so we'll try # and steal them from $HOME/.gitconfig if they are # there but missing here. gitconfig = parse_gitconfig() if gitconfig: if self.user["name"] is None: try: self.user["name"] = gitconfig["user"]["name"] except KeyError: pass if self.user["email"] is None: try: self.user["email"] = gitconfig["user"]["email"] except KeyError: pass
def setUp(self): # a random path to init trackers at self.path = get_uuid() self.env = TestEnv(False)
def setUp(self): # a path to create each test case's repo at. self.path = get_uuid()
def _rand_file(self, path): """Write a SHA1 to a file.""" with open(os.path.join(self.path, path), 'w') as fp: fp.write(get_uuid())