Giter Site home page Giter Site logo

dragomirecky / labelord_tests Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mareksuchanek/labelord_tests

0.0 1.0 0.0 214 KB

Tests for MI-PYT Labelord homework https://github.com/cvut/MI-PYT

License: Creative Commons Zero v1.0 Universal

Python 100.00%

labelord_tests's Introduction

Tests for MI-PYT Labelord homework

Usage

  1. Copy the tests files to your project.
  2. Use the skeleton of labelord.py for implementation (see notes).
  3. In your virtual environment, install pytest: python -m pip install click requests betamax flexmock pytest.
  4. Run python -m pytest tests/.

Notes:

  • You need to pass the context to click in same manner as in skeleton because it is being used in tests for injecting resources to your implementation.
  • You need to request repositories and labels with page size set explicitly to 100 and then paging (even if you need page 1) -> ?per_page=100&page=1
  • Tests use spy on session to check correct count of requests per type. Sometimes it can shadow real problem and you will see something like flexmock.MethodCallError: get() expected to be called exactly 2 times, called 0 times instead of failing assertion or thrown exception. To disable this checks you need to set environment variable LABELORD_SESSION_SPY to value off. Example for Linux:
$ export LABELORD_SESSION_SPY=off
$ python -m pytest pytest tests/
$ unset LABELORD_SESSION_SPY
$ python -m pytest pytest tests/
  • For easier work, you can use various pytest options (see documentation), for example:
    • --maxfail - to set number fails until it stops testing
    • -k - keyword expression for filtering tests
    • tests/test_file.py::test_func - give exact file as an arguments (or fully qualified test name)

Frequent errors

Error with bad request

<Result BetamaxError("A request was made that could not be handled.
A request was made to https://api.github.com/*****
The settings on the cassette are -
  record_mode: none
  match_options {'uri', 'method'}.\n",)>.exit_code

That happen if you do some requests, that tests don't expect. You can find list of allowed request urls in tests/fixtures/casettes/*

Betamax Error: object has no attribute 'message'

<[AttributeError("'BetamaxError' object has no attribute 'message'") raised in repr()] Result object at 0x7f74dbc864e0>.exit_code

This is error in Betamax library. You must edit Betamax Exception. Edit in (virtual environment): __venv__/lib/python*.*/site-packages/betamax/exceptions.py and delete lines:

def __repr__(self):
    return 'BetamaxError("%s")' % self.message

Betamax Error: A request was made that could not be handled

The tests are written in a way that thay anticipate a series of HTTP requests happening during a test. Any extra requests are "forbidden". The motivation for this is not you to have tied hands, this is happening because all HTTP coomunication is faked in the tests. When in doubt, inspect the appropriate json file in tests/fixtures/cassettes.

License

This code has been dedicated to the Public Domain, it is licensed with CC0 1.0 Universal Public Domain Dedication, full text of the license is available in the LICENSE file in this repository.

labelord_tests's People

Contributors

hroncok avatar mareksuchanek avatar wilson194 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.