Giter VIP home page Giter VIP logo

py-gardener's Introduction

Build Status Coverage Status Dependencies

Py-Gardener

Released on pypi. Install with

pip install py-gardener

What is Py-Gardener?

Py-Gardener enforces best practices for your python project.

Run Tests

Check out SETUP.md

Where can I get help?

Please open a github issue.


Getting Started

How to Integrate

Copy the example test file to the following folder with class TestGardener:

$PROJECT_DIR/tests/static/test_gardener.py

Fields:

ROOT_DIR: The root path of the project.

TEST_DIR: The test path of the project.

LIB_DIR: The source code of the project.

DOCKER: Optional list of Docker containers the project is developed against.

EXCLUDE: List of files to be not considered project files for test directory. Defaults to ["env"].

OPTIONS: General options specified below:

  • max-line-length: Default 80, max line length for pylint and PEP8 rules.

What are the tests?

Test Incorrect Bool Conditional

Test asserts don't check val in (True, False). This can result in false positives when val == 1 or val == 0.

Use isinstance(val, bool) instead

Incorrect:

>>> 0 in (True, False)
True
>>> 1 in (True, False)
True

Correct:

>>> isinstance(0, bool)
False

Test Line Endings

Test that lines do not end with backslash - use parenthesis instead

Incorrect:

assert 'key' in values or \
    condition is True

Correct:

assert (
    'key' in values or
    condition is True
)

Test PEP8

Test that we conform to PEP8.

Test Pylint

Test that we conform to Pylint.

Pylint requires a config to adhere to.

To generate the default config, run:

 $ pylint --generate-rcfile > .pylintrc

To add different configurations for sub-directories, include a separate .pylintrc at the root of the subdirectory.

Example:

$PROJECT_ROOT
|-- Dir1
|    |-- file1.py
|-- Dir2
|    |-- Dir3
|    |    |-- file2.py
|    |-- file3.py
|    |-- .pylintrc
|-- .pylintrc

In the above scenario, file1.py would be validated against $PROJECT_ROOT/.pylintrc whereas file2.py & file3.py would be validated against $PROJECT_ROOT/Dir2/.pylintrc.

PyLint Message Reference

Test Structure

Test Class Names Match

Test that test class names are correct. (Test class name must match file name)

For example:

test_Example.py

import unittest


class TestExample(unittest.TestCase):
    ...
Test Related Lib File Exists

Check test files have corresponding $LIB_DIR file if folder exists.

Example:

$TEST_DIR/dir/test_Example.py requires $LIB_DIR/dir/Example.py if $LIB_DIR/dir exists.

Test Init Files Exist

Check that all sub folders in $TEST_DIR have an __init__.py file.

Test Version Consistent

Only validates if $PROJECT_ROOT/setup.py exists

Test setup.py version doesn't fall behind git tag.

Test Docker

Only validates if DOCKER (above) is not an empty list

Test that tests are run inside a Docker container.

py-gardener's People

Contributors

macmcirish avatar pyup-bot avatar simlu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.