Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebarbaruiva committed Jan 15, 2019
1 parent 2a8e2f8 commit d8e44b9
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ venv.bak/

# mypy
.mypy_cache/

config.ini
.idea/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ Things to do to improve tool:
- Commits x Date
- Show collected info from all users on a single graphic
- Commits x Date

### Interesting links

- https://stackoverflow.com/questions/9058305/getting-attributes-of-a-class
16 changes: 16 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from configparser import ConfigParser


def get_config(section="MAIN", filename="config.ini"):
"""
Function to retrieve all information from token file.
Usually retrieves from config.ini
"""
try:
config = ConfigParser()
with open(filename) as config_file:
config.read_file(config_file)
return config[section]
except FileNotFoundError:
print("No configuration file found, check 'config_sample.ini'")
raise FileNotFoundError
6 changes: 6 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from github import Github


class Collector:
def __init__(self, access=None, user=None, password=None):
self.github = Github("user", "password")
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
invoke
green
pycodestyle
pydocstyle
coverage
pytest
PyGithub
13 changes: 13 additions & 0 deletions sample.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Real configuration file must have "config.ini" as a name to work properly
[MAIN]
# Variable "log" has as valid arguments "access_token" or "user".
# This is to identify the authentication method that'll be used
log=access_token

[GITHUB]
# This is where you'll put your credentials. Must match log.
# If log is access_token, fill access_token, the rest
# will be ignored. Example below.
access_token=THIS_IS_MY_ACCESS_TOKEN
user=
pass=
63 changes: 63 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from invoke import task

main_file = "main.py"
config_file = "config.py"
files = f"{main_file} {config_file}"
test_file = "test.py"
all_files = f"{files} {test_file}"

@task
def run(c):
""" Runs main app """
c.run(f"python3 {main_file}")


@task
def full(c):
""" Runs full battery of tests """
test(c)
cov(c)
style(c)


@task
def test(c):
""" Runs all unit and integration tests """
c.run("green3 .")


@task
def cov(c):
""" Checks code coverage """
c.run(f"coverage run -m py.test {test_file}")
c.run(f"coverage report -m {files}")
c.run(f"coverage html {files}")


@task
def html(c):
""" Opens code coverage html """
c.run("python -m webbrowser -t \"htmlcov/index.html\"")


@task
def style(c):
""" Checks for PEP8 mistakes """
c.run(f"pycodestyle {all_files} tasks.py --ignore=E402,W504")


@task
def doc(c):
""" Checks for Documentation mistakes """
c.run(f"pydocstyle {all_files}")


@task
def install(c):
""" Install all required packages """
c.run("pip install -r requirements.txt")


@task(pre=[test, style])
def travis(c):
c.run(f"coverage run -m py.test {test_file}")
29 changes: 29 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import unittest
from config import get_config
from main import Collector


class TestConfigRelated(unittest.TestCase):
def test_get_config(self):
"""
Check if all goes well when a config file can be found
"""
self.assertIn("log", get_config(filename="sample.ini"))

def test_get_config_multiple_fields(self):
"""
Check if function gets other sectors from ini file
"""
self.assertIn("access_token", get_config(section="GITHUB", filename="sample.ini"))

def test_get_config_no_file(self):
"""
Check if fails when no config file can be found
"""
with self.assertRaises(FileNotFoundError):
get_config(filename="fail.ini")


class TestCollector(unittest.TestCase):
def setUp(self):
self.collector = Collector()

0 comments on commit d8e44b9

Please sign in to comment.