Skip to content

🔖 Release v3.0.6 – Refactor, Version Bump & Changelog Update #63

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

Merged
merged 3 commits into from
Jun 7, 2025
Merged
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Changelog
## [V3.0.6] - Minor Release - 07-06-2025

- [x] Bug fixes
- [x] Updated documentation
- [x] Refactored profile generation to use dataclass for improved structure and readability
- [x] Updated tests to reflect changes in return types
- [x] Bump version to 3.0.6

## [V3.0.5] - Minor Release - 02-01-2025

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

__title__ = 'RandomProfileGenerator'
__package_name__ = 'random_profile'
__version__ = '3.0.5'
__version__ = '3.0.6'
__description__ = "Python Module To Generate Random Profile Data"
__email__ = "[email protected]"
__author__ = 'Deepak Raj'
Expand Down
2 changes: 1 addition & 1 deletion random_profile/__about__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = 'RandomProfileGenerator'
__package_name__ = 'random_profile'
__version__ = '3.0.5'
__version__ = '3.0.6'
__description__ = "Python Module To Generate Random Profile Data"
__email__ = "[email protected]"
__author__ = 'Deepak Raj'
Expand Down
117 changes: 86 additions & 31 deletions random_profile/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import uuid
import random
from typing import List, Tuple
from dataclasses import dataclass, asdict

# Ensure the current directory is in the path to import local modules
# Adjust your path as needed
sys.path.append('.')

from random_profile.enums import gender
from random_profile.enums.gender import Gender
from random_profile import utils
from random_profile.__about__ import __version__
Expand Down Expand Up @@ -42,6 +45,30 @@
job_titles = utils.load_txt_file(job_titles_txt)
job_levels = utils.load_txt_file(job_levels_txt)

@dataclass
class Profile:
id: str
gender: str
first_name: str
last_name: str
full_name: str
hair_color: str
blood_type: str
job_title: str
dob: str
age: int
phone_number: str
email: str
height: int
weight: int
ip_address: str
address: dict
full_address: str
job_experience: str
mother: str
father: str
payment_card: dict
coordinates: str

class RandomProfile:
"""
Expand Down Expand Up @@ -95,6 +122,9 @@ def __getitem__(self, index):
profiles = self.full_profiles()
return profiles[index]

def _resolve_count(self, num):
return self.num if num is None else num

def ip_address(self, num: int = None) -> List[str]:
"""Generate one or more IPv4 addresses."""
count = self.num if num is None else num
Expand All @@ -107,21 +137,21 @@ def job_title(self, num: int = None) -> List[str]:
count = self.num if num is None else num
if count == 1:
return [random.choice(job_titles)]
return random.choices(job_titles, k=count)
return random.choices(job_titles, k=self._resolve_count(num))

def blood_type(self, num: int = None) -> List[str]:
"""Generate one or more blood types."""
count = self.num if num is None else num
if count == 1:
return [random.choice(blood_types)]
return random.choices(blood_types, k=count)
return random.choices(blood_types, k=self._resolve_count(num))

def hair_color(self, num: int = None) -> List[str]:
"""Generate one or more hair colors."""
count = self.num if num is None else num
if count == 1:
return [random.choice(hair_colors)]
return random.choices(hair_colors, k=count)
return random.choices(hair_colors, k=self._resolve_count(num))

def dob_age(self, num: int = None) -> List[Tuple[str, int]]:
"""Generate DOB and age tuples."""
Expand Down Expand Up @@ -175,14 +205,14 @@ def first_names(self, num: int = None, gender: Gender = None) -> List[str]:

if count == 1:
return [random.choice(names_pool)]
return random.choices(names_pool, k=count)
return random.choices(names_pool, k=self._resolve_count(num))

def last_names(self, num: int = None) -> List[str]:
"""Generate one or more last names."""
count = self.num if num is None else num
if count == 1:
return [random.choice(lname)]
return random.choices(lname, k=count)
return random.choices(lname, k=self._resolve_count(num))

def full_names(self, num: int = None, gender: Gender = None) -> List[str]:
"""Generate one or more full names (first + last)."""
Expand Down Expand Up @@ -251,31 +281,56 @@ def full_profiles(self, num: int = None, gender: Gender = None) -> List[dict]:
card = utils.generate_random_card()

# Compose the profile dict
profile = {
'id': str(uuid.uuid4()),
'gender': this_gender.value,
'first_name': f_name,
'last_name': l_name,
'full_name': full_name,
'hair_color': [hair], # matching the list return type from hair_color()
'blood_type': [blood], # matching the list return type from blood_type()
'job_title': [random.choice(job_titles)],
'dob': dob,
'age': age,
'phone_number': phone_number,
'email': f"{f_name.lower()}{l_name.lower()}@example.com",
'height': height,
'weight': weight,
'ip_address': [utils.ipv4_gen()], # typically returns a list
'address': address_dict,
'full_address': full_address,
'job_experience': job_experience,
'mother': mother,
'father': father,
'payment_card': card,
'coordinates': coords_pretty
}

profile_list.append(profile)
# profile = {
# 'id': str(uuid.uuid4()),
# 'gender': this_gender.value,
# 'first_name': f_name,
# 'last_name': l_name,
# 'full_name': full_name,
# 'hair_color': hair, # matching the list return type from hair_color()
# 'blood_type': blood, # matching the list return type from blood_type()
# 'job_title': random.choice(job_titles),
# 'dob': dob,
# 'age': age,
# 'phone_number': phone_number,
# 'email': f"{f_name.lower()}{l_name.lower()}@example.com",
# 'height': height,
# 'weight': weight,
# 'ip_address': utils.ipv4_gen(), # typically returns a list
# 'address': address_dict,
# 'full_address': full_address,
# 'job_experience': job_experience,
# 'mother': mother,
# 'father': father,
# 'payment_card': card,
# 'coordinates': coords_pretty
# }

# profile_list.append(profile)
profile = Profile(
id=str(uuid.uuid4()),
gender=this_gender.value if this_gender.value is not None else "",
first_name=f_name,
last_name=l_name,
full_name=full_name,
hair_color=hair,
blood_type=blood,
job_title=random.choice(job_titles),
dob=dob,
age=age,
phone_number=phone_number,
email=f"{f_name.lower()}{l_name.lower()}@example.com",
height=height,
weight=weight,
ip_address=utils.ipv4_gen(),
address=address_dict,
full_address=full_address,
job_experience=job_experience,
mother=mother,
father=father,
payment_card=card,
coordinates=coords_pretty
)
profile_list.append(asdict(profile))

return profile_list
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

__title__ = 'RandomProfileGenerator'
__package_name__ = 'random_profile'
__version__ = '3.0.5'
__version__ = '3.0.6'
__description__ = "Python Module To Generate Random Profile Data"
__email__ = "[email protected]"
__author__ = 'Deepak Raj'
Expand Down
16 changes: 8 additions & 8 deletions tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class RandomProfileTest(unittest.TestCase):
# ----------------------------------------------------------------- #
def test_fname_instance(self):
self.assertIsInstance(random_profile.first_names(), str)
self.assertIsInstance(random_profile.first_names(), List)

def test_faname_with_num(self):
self.assertEqual(len(RandomProfile(num=10).first_names()), 10)
Expand All @@ -24,7 +24,7 @@ def test_fname_with_num_instance(self):

# ----------------------------------------------------------------- #
def test_lname_instance(self):
self.assertIsInstance(random_profile.last_names(), str)
self.assertIsInstance(random_profile.last_names(), List)

def test_lname_with_num(self):
self.assertEqual(len(RandomProfile(num=10).last_names()), 10)
Expand All @@ -34,7 +34,7 @@ def test_lname_with_num_instance(self):

# ----------------------------------------------------------------- #
def test_full_names_instance(self):
self.assertIsInstance(random_profile.full_names(), str)
self.assertIsInstance(random_profile.full_names(), List)

def test_full_names_with_num(self):
self.assertEqual(len(RandomProfile(num=10).full_names()), 10)
Expand All @@ -54,7 +54,7 @@ def test_full_profiles_with_num_instance(self):

# ----------------------------------------------------------------- #
def test_ipv4_instance(self):
self.assertIsInstance(random_profile.ip_address(), str)
self.assertIsInstance(random_profile.ip_address(), List)

def test_ipv4_with_num(self):
self.assertEqual(len(RandomProfile(num=10).ip_address()), 10)
Expand All @@ -64,7 +64,7 @@ def test_ipv4_with_num_instance(self):

# ----------------------------------------------------------------- #
def test_job_title_instance(self):
self.assertIsInstance(random_profile.job_title(), str)
self.assertIsInstance(random_profile.job_title(), List)

def test_job_title_with_num(self):
self.assertEqual(len(RandomProfile(num=10).job_title()), 10)
Expand All @@ -74,7 +74,7 @@ def test_job_title_with_num_instance(self):

# ----------------------------------------------------------------- #
def test_blood_type_instance(self):
self.assertIsInstance(random_profile.blood_type(), str)
self.assertIsInstance(random_profile.blood_type(), List)

def test_blood_type_with_num(self):
self.assertEqual(len(RandomProfile(num=10).blood_type()), 10)
Expand All @@ -84,7 +84,7 @@ def test_blood_type_with_num_instance(self):

# ----------------------------------------------------------------- #
def test_hair_color_instance(self):
self.assertIsInstance(random_profile.hair_color(), str)
self.assertIsInstance(random_profile.hair_color(), List)

def test_hair_color_with_num(self):
self.assertEqual(len(RandomProfile(num=10).hair_color()), 10)
Expand All @@ -94,7 +94,7 @@ def test_hair_color_with_num_instance(self):

# ----------------------------------------------------------------- #
def test_dob_age_instance(self):
self.assertIsInstance(random_profile.dob_age(), Tuple)
self.assertIsInstance(random_profile.dob_age(), List)

def test_dob_age_with_num(self):
self.assertEqual(len(RandomProfile(num=10).dob_age()), 10)
Expand Down
Loading