Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor loading configs #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions config/adjectives.yml

This file was deleted.

9 changes: 5 additions & 4 deletions pyfake/adjective.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from .generator import Generator
from pathlib import Path
import random
import yaml

with open(str(Path(__file__).parent) + '/config/adjectives.yml', 'r') as file:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do a bit simpler: open(Path(__file__).parent / "config/adjectives.yml) as file or even just yaml.safe_load((Path(__file__).parent / "config/adjectives.yml).read_text())

CONFIG = yaml.safe_load(file)

class Adjective(Generator):
with open("config/adjectives.yml", "r") as file:
CONFIG = yaml.safe_load(file)

def adjective(self):
return random.choice(self.CONFIG["adjectives"])
print(CONFIG)
return random.choice(CONFIG)

def generate(self):
self.adjective = self.adjective()
3 changes: 2 additions & 1 deletion pyfake/book.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .generator import Generator
from pathlib import Path
import random
import yaml

with open('config/books.yml', 'r') as file:
with open(str(Path(__file__).parent) + '/config/books.yml', 'r') as file:
CONFIG = yaml.safe_load(file)

class Book(Generator):
Expand Down
11 changes: 6 additions & 5 deletions pyfake/company.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from .generator import Generator
from pathlib import Path
import random
import yaml

class Company(Generator):
with open('config/company.yml', 'r') as file:
CONFIG = yaml.safe_load(file)
with open(str(Path(__file__).parent) + '/config/company.yml', 'r') as file:
CONFIG = yaml.safe_load(file)

class Company(Generator):
def company_name(self):
return random.choice(self.CONFIG['names'])
return random.choice(CONFIG['names'])

def company_suffix(self):
return random.choice(self.CONFIG['suffixes'])
return random.choice(CONFIG['suffixes'])

def generate(self):
self.size = random.randint(1, 100)
Expand Down
Empty file added pyfake/config.py
Empty file.
57 changes: 57 additions & 0 deletions pyfake/config/adjectives.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
- arrogant
- beautiful
- best
- biggest
- circular
- competent
- confusing
- courageous
- cumbersome
- dainty
- dark
- devoted
- efficient
- expensive
- fickle
- generous
- graceful
- grumpy
- happiest
- helpful
- hopeful
- hot
- hungry
- mild
- modern
- muscular
- new
- new
- oldest
- oval
- petite
- prettiest
- proud
- rich
- rocky
- round
- round
- royal
- rude
- safe
- scary
- sleepy
- small
- smart
- smelly
- stable
- strange
- strange
- tardy
- thin
- weary
- wicked
- witty
- wooden
- youthful
- zany
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions pyfake/country.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from .generator import Generator
from pathlib import Path
import yaml
import random

class Country(Generator):
with open('config/countries.yml', 'r') as file:
CONFIG = yaml.safe_load(file)
with open(str(Path(__file__).parent) + '/config/countries.yml', 'r') as file:
CONFIG = yaml.safe_load(file)

class Country(Generator):
def generate(self):
data = random.choice(self.CONFIG)
data = random.choice(CONFIG)

self.name = data['name']
self.currency = data['currency']
Expand Down
9 changes: 5 additions & 4 deletions pyfake/person.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from .generator import Generator
from pathlib import Path
import random
import yaml

class Person(Generator):
with open('config/people.yml', 'r') as file:
CONFIG = yaml.safe_load(file)
with open(str(Path(__file__).parent) + '/config/people.yml', 'r') as file:
CONFIG = yaml.safe_load(file)

class Person(Generator):
def generate(self):
data = random.choice(self.CONFIG)
data = random.choice(CONFIG)

self.first_name = data['first_name']
self.last_name = data['last_name']
Expand Down
9 changes: 5 additions & 4 deletions pyfake/sport.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from .generator import Generator
from pathlib import Path
import yaml
import random

class Sport(Generator):
with open('config/sports.yml', 'r') as file:
CONFIG = yaml.safe_load(file)
with open(str(Path(__file__).parent) + '/config/sports.yml', 'r') as file:
CONFIG = yaml.safe_load(file)

class Sport(Generator):
def generate(self):
data = random.choice(self.CONFIG)
data = random.choice(CONFIG)

self.name = data['name']
self.players = data['players']
Expand Down
2 changes: 1 addition & 1 deletion tests/test_adjective.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
def test_adjective():
adj = Adjective().adjective

assert adj in Adjective().CONFIG['adjectives']
assert isinstance(adj, str)
Loading