def test_side_by_side(self): s = "{status} [{artist} / [{album} / ]]{title}[ {song_elapsed}/{song_length}]" assert util.formatp(s, status="▷", title="Only For The Weak", song_elapsed="1:41", song_length="4:55") == "▷ Only For The Weak 1:41/4:55" assert util.formatp( s, status="", album="Foo", title="Die, Die, Crucified", song_elapsed="2:52") == " Die, Die, Crucified" assert util.formatp("[[{a}][{b}]]", b=1) == "1"
def test_complex_field(self): class NS: pass obj = NS() obj.attr = "bar" s = "[{a:.3f} m]{obj.attr}" assert util.formatp(s, a=3.14123456789, obj=obj) == "3.141 mbar" assert util.formatp(s, a=0.0, obj=obj) == "bar"
def test_nesting(self): s = "[[{artist} - ]{album} - ]{title}" assert util.formatp(s, title="Black rose") == "Black rose" assert util.formatp( s, artist="In Flames", title="Gyroscope") == "Gyroscope" assert util.formatp( s, artist="SOAD", album="Toxicity", title="Science") == "SOAD - Toxicity - Science" assert util.formatp( s, album="Toxicity", title="Science") == "Toxicity - Science"
def test_nesting(self): s = "[[{artist} - ]{album} - ]{title}" assert util.formatp(s, title="Black rose") == "Black rose" assert util.formatp(s, artist="In Flames", title="Gyroscope") == "Gyroscope" assert util.formatp(s, artist="SOAD", album="Toxicity", title="Science") == "SOAD - Toxicity - Science" assert util.formatp(s, album="Toxicity", title="Science") == "Toxicity - Science"
def test_side_by_side(self): s = "{status} [{artist} / [{album} / ]]{title}[ {song_elapsed}/{song_length}]" assert util.formatp( s, status="▷", title="Only For The Weak", song_elapsed="1:41", song_length="4:55") == "▷ Only For The Weak 1:41/4:55" assert util.formatp(s, status="", album="Foo", title="Die, Die, Crucified", song_elapsed="2:52") == " Die, Die, Crucified" assert util.formatp("[[{a}][{b}]]", b=1) == "1"
def run(self): if self.travis is None: self.travis = TravisPy.github_auth(self.github_token) repo = self.travis.repo(self.repo_slug) self.repo_status = self.repo_status_map.get(repo.last_build_state, repo.last_build_state) self.last_build_id = repo.last_build_id if repo.last_build_state == 'started': self.last_build_finished = None self.last_build_duration = None elif repo.last_build_state in ('failed', 'errored', 'cancelled', 'passed'): self.last_build_finished = self._format_time(repo.last_build_finished_at) self.last_build_duration = TimeWrapper(repo.last_build_duration, default_format=self.duration_format) self.output = dict( full_text=formatp(self.format, **vars(self)), short_text=self.short_format.format(**vars(self)), ) if self.status_color_map: self.output['color'] = self.status_color_map.get(repo.last_build_state, self.color) else: self.output['color'] = self.color
def run(self): if self.circleci is None: self.circleci = Api(self.circleci_token) if self.workflows: if self.workflow_branch and not self.workflow_name: self.output = dict( full_text='workflow_name must be specified!' ) return project = {p['reponame']: p for p in self.circleci.get_projects()}.get(self.repo_name) if not self.workflow_branch: self.workflow_branch = project.get('default_branch') workflow_info = project['branches'].get(self.workflow_branch)['latest_workflows'].get(self.workflow_name) self.last_build_started = self._format_time(workflow_info.get('created_at')) self.repo_status = workflow_info.get('status') self.last_build_duration = '' # TODO: gather this information once circleCI exposes it else: self.repo_summary = self.circleci.get_project_build_summary( self.repo_owner, self.repo_name, limit=1) if len(self.repo_summary) != 1: return self.repo_summary = self.repo_summary[0] self.repo_status = self.repo_summary.get('status') self.last_build_started = self._format_time(self.repo_summary.get('queued_at')) try: self.last_build_duration = TimeWrapper( self.repo_summary.get('build_time_millis') / 1000, default_format=self.duration_format) except TypeError: self.last_build_duration = 0 if self.repo_status_map: self.repo_status = self.repo_status_map.get(self.repo_status, self.repo_status) self.output = dict( full_text=formatp(self.format, **vars(self)), short_text=self.short_format.format(**vars(self)), ) if self.status_color_map: self.output['color'] = self.status_color_map.get(self.repo_status, self.color) else: self.output['color'] = self.color
def run(self): pd_incidents = pypd.Incident.find(**self.api_search_dict) incidents = { 'acknowledged': [], 'triggered': [], 'all': [] } for incident in pd_incidents: incidents['all'].append(incident) status = incident.get('status') if status == 'acknowledged': incidents['acknowledged'].append(incident) elif status == 'triggered': incidents['triggered'].append(incident) self.num_acknowledged_incidents = len(incidents.get('acknowledged')) self.num_triggered_incidents = len(incidents.get('triggered')) self.num_incidents = len(incidents.get('all')) self.output = dict( full_text=formatp(self.format, **vars(self)), color=self.color )
def test_presuffix(self): assert util.formatp("ALINA[{title} schnacke]KOMMAHER", title="") == "ALINAKOMMAHER" assert util.formatp("grml[{title}]") == "grml" assert util.formatp("[{t}]grml") == "grml"
def test_bare(self): assert util.formatp("{foo} blar", foo="bar") == "bar blar"
def test_numerical(self): assert util.formatp("[{t} - [schmuh {x}]]", t=1, x=2) == "1 - schmuh 2" assert util.formatp("[{t} - [schmuh {x}]]", t=1, x=0) == "1 - " assert util.formatp("[{t} - [schmuh {x}]]", t=0, x=0) == ""
def test_escaping(self): assert util.formatp(r"[razamba \[ mabe \]]") == "razamba [ mabe ]"
def test_escaping(self): assert util.formatp("[razamba \[ mabe \]]") == "razamba [ mabe ]"
# This would look like this, when discharging (or charging) # ↓14.22W 56.15% [77.81%] 2h:41m # And like this if full: # =14.22W 100.0% [91.21%] # # This would also display a desktop notification (via D-Bus) if the percentage # goes below 5 percent while discharging. The block will also color RED. # If you don't have a desktop notification demon yet, take a look at dunst: # http://www.knopwob.org/dunst/ status.register("battery", format="{status} {percentage:.2f}% {remaining:%E%hh:%Mm}", alert=True, alert_percentage=10, status={ "DIS": formatp("↓ {percentage:.2f}% {remaining:%E%hh:%Mm}"), "CHR": " {percentage:.2f}% {remaining:%E%hh:%Mm}", "FULL": "= {percentage:.2f}% {remaining:%E%hh:%Mm}", },) # This would look like this: # Discharging 6h:51m status.register("battery", format="{status} {remaining:%E%hh:%Mm}", alert=True, alert_percentage=5, status={ "DIS": "Discharging", "CHR": "Charging", "FULL": "Bat full", },)