-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a8e2f8
commit d8e44b9
Showing
8 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,6 @@ venv.bak/ | |
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
config.ini | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
invoke | ||
green | ||
pycodestyle | ||
pydocstyle | ||
coverage | ||
pytest | ||
PyGithub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |