GithubHelp home page GithubHelp logo

dkotschessa / faker_airtravel Goto Github PK

View Code? Open in Web Editor NEW
13.0 13.0 9.0 244 KB

A community provider for the python faker library to fake airline data for testing purposes.

Home Page: https://pypi.org/project/faker_airtravel/

License: MIT License

Python 100.00%
airtravel faker testing

faker_airtravel's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

faker_airtravel's Issues

Use random from provider's generator

Hey ๐Ÿ‘‹

Problem statement

I was looking into the source code of this project, namely AirTravelProvider(source) and I noticed that the random generation uses python's random, rather than the shared random in generator. This raises a reproducibility concern (among others), namely the provider not following the seed set by Generator.seed(<seed>).

Proposed solution

Update the provider, replacing random.* usages by self.generator.random.* (example).

I'm open to create a PR with the proposed solution ๐Ÿ‘

direct command line example using faker_airtravel provider

Hi, im aware of using python script to generate airport data like:
python -c "from faker import Faker; from faker_airtravel import AirTravelProvider; fake = Faker(); fake.add_provider(AirTravelProvider); airports = [fake.airport_name() for _ in range(10)]; print(airports)"
and returns as expected:

['Kahului airport', 'Taiyuan Wusu airport', 'Carriel Sur International airport', 'Fukuoka airport', 'Gustavia airport', 'Santa Maria airport', 'Salta airport', 'Tacoma International airport', 'Camilo Daza airport', 'Senador Nilo Coelho airport']

  1. But Im struggling how to generate the same using faker without python, via faker -i command line option:
$ faker -i faker_airtravel airport_name
AttributeError: module 'faker_airtravel' has no attribute 'Provider'

$ faker -i faker_airtravel.AirTravelProvider airport_name
ModuleNotFoundError: No module named 'faker_airtravel.AirTravelProvider'

$ faker -i AirTravelProvider airport_name
ModuleNotFoundError: No module named 'AirTravelProvider'

Thanks (and sorry as this is not really an issue with faker_airtravel, but google only returns python examples and couldn't find command line example executing faker with -i to add community provider.

2- additionally I installed faker_airtravel via pip, but couldn't understand how to install via conda, seems i need to specify some "channel", i wonder how to do that (I'm not hard core python developer). Heres pip install ok:

$ pip install faker_airtravel
Collecting faker_airtravel
  Using cached faker_airtravel-0.4-py2.py3-none-any.whl (18 kB)
Installing collected packages: faker_airtravel
Successfully installed faker_airtravel-0.4

And conda giving error about channel:

$ conda install faker_airtravel
Collecting package metadata (current_repodata.json): done
Solving environment: unsuccessful initial attempt using frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: unsuccessful initial attempt using frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  - faker_airtravel

Current channels:

  - https://repo.anaconda.com/pkgs/main/win-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/win-64
  - https://repo.anaconda.com/pkgs/r/noarch
  - https://repo.anaconda.com/pkgs/msys2/win-64
  - https://repo.anaconda.com/pkgs/msys2/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.

Restrict flights to specific countries

I think a great option would be to restrict flights from and to specific countries.

An example would be: Flights from USA and airports LAX or DFW as an example.

Bug: "flight' is broken: may return the same origin and destination.

Code to reproduce:

from faker import Faker
from faker_airtravel import AirTravelProvider


fake = Faker()
for provider in (AirTravelProvider, ):
    fake.add_provider(provider)

for _ in range(10_000):
    random_flight = fake.flight()
    d_iata = random_flight["origin"]["iata"]
    a_iata = random_flight["destination"]["iata"]
    print(f'{random_flight["origin"]} -> {random_flight["destination"]}')
    assert d_iata != a_iata

"Origin" and "destination" may be the same.

UPD:
You use random.choices. It will not give you elements without repetition out of the box. This is why the bug appears.

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.