Skip to content

Commit

Permalink
Change behavior to print the banner_comment by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jbn committed Jul 9, 2016
1 parent ea2a644 commit f0e239c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,6 @@ build
*.pyc
MANIFEST
dist
banner_comment.iml
banner_comment.egg-info
.idea
13 changes: 13 additions & 0 deletions .travis.yml
@@ -0,0 +1,13 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.5-dev" # 3.5 development branch
- "nightly" # currently points to 3.6-dev
before_install:
- sudo apt-get install -y figlet
install: "pip install coveralls nose"
script: coverage run --source=banner_comment setup.py nosetests
after_success: coveralls
11 changes: 9 additions & 2 deletions README.md
@@ -1,15 +1,22 @@
[![Build Status](https://travis-ci.org/jbn/banner_comment.svg?branch=master)](https://travis-ci.org/jbn/banner_comment)
[![Coverage Status](https://coveralls.io/repos/github/jbn/banner_comment/badge.svg?branch=master)](https://coveralls.io/github/jbn/banner_comment?branch=master)
<!-- LOL: Coverage on a one function module -->

# What is this?

I like banner comments in my code. Modern IDE's have fancier ways of doing this like code collapsing and such. And, Python style guides generally prohibit this style of commenting. But, I like to see the big test while scrolling (or, in [`subl`](https://www.sublimetext.com/)).

# Example

Running this:

```python
from banner_comment import *
print(banner_comment("hello"))
banner_comment("hello")
```

## Outputs...
Prints:

```
###############################################################################
# _ _ _ #
Expand Down
12 changes: 10 additions & 2 deletions banner_comment/__init__.py
@@ -1,17 +1,21 @@
from __future__ import print_function
import subprocess


def banner_comment(text, font='ogre', width=79,
def banner_comment(text, font='standard', width=79, print_to_stdout=True,
border_top=True, border_bottom=True, border_right=True):
"""
Generate a ASCII Banner comment for separating code blocks via FIGlet.
:param text: The text to banner-ize.
:param font: the figlet font
:param width: the column width of the banner
:param print_to_stdout: if True (default) print the banner comment to
stdout. Otherwise, print nothing.
:param border_top: print a octothorp border on the top
:param border_bottom: print a octothorp border on the bottom
:param border_right: print a octothorp border on the right
:return: the banner_comment, if print_to_stdout is False
"""
cmd = ['figlet', '-c', '-w', str(width), '-f', font, text]
s = subprocess.check_output(cmd).decode()
Expand All @@ -28,4 +32,8 @@ def banner_comment(text, font='ogre', width=79,
if border_bottom:
lines.append(border)

return "\n".join(lines) + "\n"
banner_str = "\n".join(lines) + "\n"
if print_to_stdout:
print(banner_str, end='')
else:
return banner_str
Empty file added requirements.txt
Empty file.
8 changes: 4 additions & 4 deletions setup.py
@@ -1,14 +1,14 @@

from distutils.core import setup
from setuptools import setup

setup(
name="banner_comment",
version="0.0.2",
version="0.0.3",
packages=["banner_comment"],
license="License :: OSI Approved :: MIT License",
author="John Bjorn Nelson",
author_email="jbn@abreka.com",
description="An ASCII banner comment generator for making subl nicer.",
long_description=open("README.md").read(),
url="https://github.com/jbn/banner_comment"
url="https://github.com/jbn/banner_comment",
setup_requires=['nose>=1.0']
)
14 changes: 11 additions & 3 deletions tests/test_banner_comment.py
@@ -1,3 +1,4 @@
import sys
import unittest
from banner_comment import banner_comment

Expand All @@ -11,13 +12,20 @@
# |_| |_|\___|_|_|\___/ #
# #
###############################################################################
"""
""".strip() + "\n"


class TestBannerComment(unittest.TestCase):
def test_banner_comment(self):
def test_banner_comment_as_str(self):
result = banner_comment("hello", print_to_stdout=False)
self.assertEqual(EXPECTED, result)

def test_banner_comment_printed(self):
if not hasattr(sys.stdout, "getvalue"):
self.fail("need to run in buffered mode")
result = banner_comment("hello")
self.assertEqual(EXPECTED.strip()+"\n", result)
self.assertIsNone(result)
self.assertEqual(EXPECTED, sys.stdout.getvalue())


if __name__ == '__main__':
Expand Down

0 comments on commit f0e239c

Please sign in to comment.