\[ \definecolor{data}{RGB}{18,110,213} \definecolor{unknown}{RGB}{217,86,16} \definecolor{learned}{RGB}{175,114,176} \]

3gpp-citation - testing assignment

WASP Software Engineering and Cloud Computing

Martin Isaksson
Ericsson Research | KTH EECS | RISE AI

3gpp-citations

My software project

This project aims to generate BiBTeX files that can be used when citing 3GPP specifications. The input is a document list exported from the 3GPP Portal.

3gpp-citations -i 2019-02-27_0833_SpecificationList_077fb5.xlsx -o 3gpp-38-series.bib
@techreport{3gpp.38.322,
 author = {3GPP},
 day = {11},
 institution = {{3rd Generation Partnership Project (3GPP)}},
 month = {1},
 note = {Version 15.4.0},
 number = {38.322},
 title = {{NR; Radio Link Control (RLC) protocol specification}},
 type = {Technical Specification (TS)},
 url = {http://www.3gpp.org/DynaReport/38322.htm},
 year = {2019}
}

The test framework

pytest

def inc(x):
    return x + 1

def test_answer():
    assert inc(3) == 5
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 item
test_sample.py F                                                     [100%]
================================= FAILURES =================================
_______________________________ test_answer ________________________________
    def test_answer():
>       assert inc(3) == 5
E       assert 4 == 5
E        +  where 4 = inc(3)
test_sample.py:6: AssertionError
========================= 1 failed in 0.12 seconds =========================

The test framework

Travis CI

Build Status

  • My Github account is linked to my Travis CI account.
  • Used for testing and deployment.
  • A .travis.yml defines the CI pipeline.
language: python
python:
  - 2.7
  - 3.5
  - 3.6
  - 3.7
dist: bionic
sudo: true
install:
  - pip install -e .[test]
script:
  - make test

The test framework

Coveralls

Coverage Status

py.test \
    --cov standardcitations --cov-report term-missing
  • In .travis.yml add
after_success:
  - coveralls

The test framework

Flakes, PEP8, durations and lint

  • pyflakes analyzes programs and detects various errors.
  • pep8 is a tool to check your Python code against some of the style conventions in PEP 8.
  • pylint It's not just a linter that annoys you!
  • --durations=10 lists the 10 tests that take the longest time

  • The full pytest command line is

py.test \
  --pylint --pylint-jobs=4  \
  --flakes --doctest-modules \
  --pep8 standardcitations -v \
  --cov standardcitations --cov-report term-missing \
  --durations=10

Also worth checking out

The test cases

Tree structure

.
├── Makefile
├── bin
│   └── 3gpp-citations
├── setup.py
└── standardcitations
    ├── __init__.py
    ├── standardcitations.py
    └── test
        ├── test_format_entry.py
        ├── test_format_url.py
        ├── test_get_bibdatabase.py
        ├── test_get_entry.py
        ├── test_get_worksheet.py
        ├── test_input.xlsx
        ├── test_main.py
        ├── test_parse_args.py
        ├── test_parse_date.py
        ├── test_parse_excel_row.py
        └── test_write_bibtex.py

The test cases

An example

  • Is it enough that it starts with @techreport?
def test_write_bibtex_stdout(capsys):
    """
    Test function that prints to stdout (with single entry). We test
    here that with one input we get one output of the correct type.
    (The correctness of the entire output is verified elsewhere.)
    """

    database = standardcitations.get_bibdatabase()

    worksheet = standardcitations.get_worksheet(
        "standardcitations/test/test_input.xlsx")

    row = worksheet.__getitem__('2')
    entry = standardcitations.get_entry(row, True)

    database.entries.append(entry)
    standardcitations.write_bibtex(database)
    captured = capsys.readouterr()
    assert captured.out.startswith("@techreport")

The test cases

Another example

  • Tests URL format is valid, but doesn't test that it's correct.
import validators
from standardcitations import standardcitations


def test_format_url():
    """
    This function tests the `format_url` function so that it produces
    valid urls (without the break points)
    """

    url = standardcitations.format_url("36.331", False)
    assert validators.url(url)

Challenges in my area

Thanks everyone!

www website
github martisak