Пример #1
0
def test_GA_unsupported_table_name():
    """
    creating a table that is unsupported
    """
    db = 'test'
    table = 'unsupported_table_name'

    # create the database handler object
    db = GithubIssuesDB(db, table, echo=False)
    assert db.status == 1  # ERROR 1: unsupported table name

    # clean up after test
    status = db.drop_db()
    assert status == 16  # WARNING 16: db file does not exist
Пример #2
0
def test_GA_invalid_table_drop():
    """
    correct handling of invalid table drops
    """
    db = 'test'
    table = 'issues'

    # create the database handler object
    db = GithubIssuesDB(db, table, echo=False)
    assert db.status == 0  # SUCCESS

    # prepare test conditions - remove old db file if one exists
    if os.path.exists(db.db_file):
        status = db.drop_db()
        assert status == 0  # SUCCESS

    # create issues table (this creates a new db file)
    status = db.create_table()
    assert status == 0  # SUCCESS

    # drop issues table
    status = db.drop_table()
    assert status == 0  # SUCCESS

    # attempt to drop issues table again
    status = db.drop_table()
    assert status == 3  # ERROR 3: non-existent table

    # clean up after test
    status = db.drop_db()
    assert status == 0  # SUCCESS
Пример #3
0
def test_GA_duplicate_table():
    """
    creating a duplicate db table
    """
    db = 'test'
    table = 'issues'

    # create the database handler object
    db = GithubIssuesDB(db, table, echo=False)
    assert db.status == 0  # SUCCESS

    # prepare test conditions - remove old db file if one exists
    if os.path.exists(db.db_file):
        status = db.drop_db()
        assert status == 0  # SUCCESS

    # create issues table (this creates a new db file)
    status = db.create_table()
    assert status == 0  # SUCCESS

    # attempt to create another issues table
    status = db.create_table()
    assert status == 4  # ERROR 4: table already exists

    # clean up after test
    status = db.drop_db()
    assert status == 0  # SUCCESS
Пример #4
0
def test_GA_db_drop():
    """
    database file removal
    When/if we encounter an ERROR 15, we'll need to cater for it
    """
    db = 'test'
    table = 'issues'

    # create the database handler object
    db = GithubIssuesDB(db, table, echo=False)
    assert db.status == 0  # SUCCESS

    # remove old db file if one exists
    if os.path.exists(db.db_file):
        status = db.drop_db()
        assert status == 0  # SUCCESS

    # create a table (this creates a new db file)
    status = db.create_table()
    assert status == 0  # SUCCESS

    # delete the db file that's just been created
    status = db.drop_db()
    assert status == 0  # SUCCESS

    # attempt deletion of (now) non-existent db file
    status = db.drop_db()
    assert status == 16  # WARNING 16: db file does not exist
Пример #5
0
def test_GA_bad_file_permissions():
    """
    failure to create a db file due to bad permissions
    """
    path = '/tmp/githubissues-test/'
    db = path + 'test'
    table = 'issues'

    # create a folder with zero permissions
    if not os.path.exists(path):
        os.makedirs(path)
        os.chmod(path, 0o000)

    # create the database handler object
    db = GithubIssuesDB(db, table, echo=False)
    assert db.status == 0  # SUCCESS

    # attempt to create a table (which would create a new db file)
    status = db.create_table()
    assert status == 4  # ERROR 4: unable to create db file

    # clean up after test
    os.chmod(path, 0o777)
    os.rmdir(path)
Пример #6
0
def test_GID_analysis_period_range_checks(args):
    """
    tests for both in-range and out-of-range analysis periods
    (compares issues list time span with analysis period time span and adjusts with warnings)
    """
    db_name = 'test'
    table_name = 'issues'
    url_args = {'account': 'matplotlib', 'repo': 'matplotlib', 'first_page': 1}

    db = GithubIssuesDB(db_name, table_name, echo=False)
    assert db.status == 0  # SUCCESS

    # prepare test conditions - remove old db file if one exists
    if os.path.exists(db.db_file):
        status = db.drop_db()
        assert status == 0  # SUCCESS

    # create issues table (this creates a new db file)
    status = db.create_table()
    assert status == 0  # SUCCESS

    ga = GithubIssuesAPI()
    ga.set_seed_url(url_args)
    assert ga.status == 0  # SUCCESS

    gd = GithubIssuesData()
    assert gd.status == 0  # SUCCESS

    # request N pages and process data into a database
    for page in range(0, 1):
        ga.get_next_page()
        for issue in ga.response.json():
            db.insert_issue(issue)
    assert db.status == 0  # SUCCESS

    # initialise plotting data arrays (y axes)
    # and create an array of month labels (x-axis)
    gd.init_arrays(db.monthly_span)
    assert gd.status == 0  # SUCCESS
    assert len(gd.plot_points) == 3
    assert len(gd.opened_issue_counts) == 3
    assert len(gd.closed_issue_counts) == 3
    assert len(gd.total_open_issue_counts) == 3
    assert len(gd.issue_ages) == 0
    assert len(gd.month_labels) == 3
    assert gd.month_labels[0] == ''
    assert gd.month_labels[1] == 'Mar-11'
    assert gd.month_labels[2] == 'Apr-11'

    # start date prior to issues list date range
    [w_start, w_end] = gd.set_plot_window(args)
    assert gd.status == args['status']  # WARN
    assert w_start == args['start']
    assert w_end == args['end']
Пример #7
0
def test_GID_no_issues():
    """
    processing an issues list that only has a single page of issues
    (the earliest page of the numpy issues list has zero open issues)
    """

    db_name = 'test'
    table_name = 'issues'
    args = {'account': 'numpy',
            'repo': 'numpy',
            'issue_type': 'issue',
            'first_page': 1,
            'page_count': 1}

    ga = GithubIssuesAPI()
    ga.set_seed_url(args)
    assert ga.status == 0  # SUCCESS

    # create the database handler object
    db = GithubIssuesDB(db_name, table_name, echo=False)
    assert db.status == 0  # SUCCESS

    # prepare test conditions - remove old db file if one exists
    if os.path.exists(db.db_file):
        status = db.drop_db()
        assert status == 0  # SUCCESS

    # create issues table (this creates a new db file)
    status = db.create_table()
    assert status == 0  # SUCCESS

    for page in range(0, args['page_count']):
        ga.get_next_page()
        for issue in ga.response.json():
            db.insert_issue(issue)
    assert db.status == 0  # SUCCESS
    assert db.count_records("issue") == 0
Пример #8
0
### NUMPY:      https://docs.scipy.org/doc/numpy/reference/   ###
### MATPLOTLIB: https://matplotlib.org/3.1.1/tutorials        ###
#################################################################

gu = GithubIssuesUtils()
args = gu.process_args()
args = gu.args

# simply write debug info to a file and quit if -i/--info arg is supplied
if args['info'] == True:
    gu.write_debug_info()
    exit()

# wipe and create an empty issues database table with every run
# (future versions may implement incremental update capabilities)
db = GithubIssuesDB(f'{gu.data_path}/issues', 'issues', echo=False)
# initialise object for interfacing with GtihubAPI
ga = GithubIssuesAPI()
# initialise data structures for plotting data
gd = GithubIssuesData()

db.drop_table('issues')
db.create_table('issues')

db.drop_table('labels')
db.create_table('labels')

# read in issue labels (multiple-pages)
ga.set_seed_url(args, 'labels')
for page in range(0, args['page_count']):
    ga.get_next_page(args)
Пример #9
0
import matplotlib.patches as mpatches
from mpl_toolkits.axes_grid1.inset_locator import inset_axes

#################################################################
### ONLINE REFERENCES                                         ###
### PANDAS:     https://pandas.pydata.org/pandas-docs/stable/ ###
### SQLITE:     https://sqlite.org/docs.html                  ###
### NUMPY:      https://docs.scipy.org/doc/numpy/reference/   ###
### MATPLOTLIB: https://matplotlib.org/3.1.1/tutorials        ###
#################################################################

gu = GithubIssuesUtils()
args = gu.process_args()
args = gu.args

db = GithubIssuesDB(f'{gu.data_path}/issues', 'issues', echo=False)
# wipe and regenerate the issues database with every run.
# future versions may implement more extensive CRUD capabilities
db.drop_table()
db.create_table()

# collect issues data via Gtihub API (JSON)
ga = GithubIssuesAPI()
ga.set_seed_url(args)
for page in range(0, args['page_count']):
    ga.get_next_page(args)
    for issue in ga.response.json():
        db.insert_issue(issue)
    # stop when we've reached last page of issues
    if ga.status == 202:
        break