Ejemplo n.º 1
0
def json_hook(obj):
    if 'set' in obj:
        return set(obj)
    car_args = object_comparison(obj, Car)
    cesar_args = object_comparison(obj, Cesar)
    garage_args = object_comparison(obj, Garage)

    if all(car_args):
        create_car = Car(
            price=obj['price'],
            type_car=obj['type_car'],
            producer=obj['producer'],
            mileage=obj['mileage']
        )
        create_car.number = obj['number']
        return create_car

    if all(garage_args):
        create_garage = Garage(
            town=obj['town'],
            places=obj['places'],
            cars=obj['cars'],
            owner=obj['owner']
        )
        return create_garage

    if all(cesar_args):
        create_cesar = Cesar(name=obj['name'], garages=obj['garages'])
        create_cesar.register_id = obj['register_id']
        return create_cesar

    return obj
Ejemplo n.º 2
0
 def test_add_car(self):
     cesar = Cesar('Alfred')
     garage_1 = Garage(4)
     garage_2 = Garage(2)
     garage_3 = Garage(8)
     car_1 = Car(25000, 10000)
     car_2 = Car(30000, 5000)
     cesar.add_garage(garage_1)
     cesar.add_garage(garage_2)
     cesar.add_garage(garage_3)
     cesar.add_car(car_1, garage_1)  # add car with specific garage
     cesar.add_car(car_2)  # add car without specific garage
     self.assertEqual(garage_1.free_place(), 3)  # check our method
     self.assertEqual(garage_3.free_place(), 7)  # check our method
Ejemplo n.º 3
0
 def test_garages_count(self):
     cesar = Cesar('Alfred')
     garage_1 = Garage(4)
     garage_2 = Garage(2)
     garage_3 = Garage(8)
     cesar.add_garage(garage_1)
     cesar.add_garage(garage_2)
     cesar.add_garage(garage_3)
     self.assertEqual(cesar.garages_count(), 3)
Ejemplo n.º 4
0
    garages_list = [
        Garage(town=random.choice(TOWNS), places=random.randint(1, 7))
        for _ in range(3)
    ]
    garages_list2 = [
        Garage(town=random.choice(TOWNS), places=3) for _ in range(4)
    ]

    gara = Garage(town='Amsterdam', places=3)
    gara2 = Garage(town='Prague', places=3)
    for car in cars_list:
        gara.add(car)
    gara.add(ford)
    gara2.add(ford)
    gara2.add(bmw)
    cesas = Cesar('Petro', garages_list)
    cesas2 = Cesar('Vasia', garages_list2)
    cesas3 = Cesar('Oleg', [gara])

    print('*' * 20, 'JSON', '*' * 20)
    cr_damp = JsonConverter.json_damps(bmw)
    print(type(cr_damp), cr_damp)
    bmw2 = JsonConverter.json_loads(cr_damp)
    print(type(bmw2), bmw2)
    cr_gara_damps = JsonConverter.json_damps(gara)
    loads_gara_damps = JsonConverter.json_loads(cr_gara_damps)

    cr_cesar_damps = JsonConverter.json_damps(cesas)
    loads_cesar_damps = JsonConverter.json_loads(cr_cesar_damps)

    cr_cesar_damp = JsonConverter.json_damp('cesar_damp', cesas)
def cesar_from_json(data):
    name = data['name']
    heorh = Cesar(name=name)
    return heorh
Advanced
Добавити опрацьовку формату ini
"""
from objects_and_classes.homework.homework import (
    Cesar,
    Garage,
    Car
    )
import json
import ruamel.yaml
from ruamel.yaml import YAML
import pickle


heorh = Cesar('Heorh')
king_garage = Garage(4)
elite_car = Car(500000, 5000)

# ___________convert by JSON____________


def heorh_to_json(obj: Cesar):
    data = {'name': obj.name}
    return data


def king_garage_to_json(obj: Garage):
    data = {'places': obj.places, 'owner': None}
    return data
Ejemplo n.º 7
0
 def test_add_garage(self):
     cesar = Cesar('Alfred')
     garage_1 = Garage(6)
     cesar.add_garage(garage_1)
     self.assertEqual(len(cesar.garages), 1)
Ejemplo n.º 8
0
 def test_equal(self):
     cesar_1 = Cesar('Alfred')
     cesar_2 = Cesar('Hector')
     garage_1 = Garage(2)
     garage_2 = Garage(2)
     garage_3 = Garage(2)
     garage_4 = Garage(2)
     car_1 = Car(100, 10000)
     car_2 = Car(100, 5000)
     car_3 = Car(100, 500)
     car_4 = Car(100, 50)
     car_5 = Car(100, 50000)
     car_6 = Car(100, 500000)
     cesar_1.add_garage(garage_1)
     cesar_1.add_garage(garage_2)
     cesar_2.add_garage(garage_3)
     cesar_2.add_garage(garage_4)
     cesar_1.add_car(car_1, garage_1)
     cesar_1.add_car(car_2, garage_2)
     cesar_1.add_car(car_3, garage_2)
     cesar_2.add_car(car_4, garage_3)
     cesar_2.add_car(car_5, garage_4)
     cesar_2.add_car(car_6, garage_4)
     self.assertEqual(cesar_1.hit_hat(), cesar_2.hit_hat())
Ejemplo n.º 9
0
 def test_hit_hat(self):
     cesar = Cesar('Alfred')
     garage_1 = Garage(4)
     garage_2 = Garage(2)
     garage_3 = Garage(8)
     car_1 = Car(25000, 10000)
     car_2 = Car(30000, 5000)
     car_3 = Car(3000, 500)
     car_4 = Car(300, 50)
     car_5 = Car(300000, 50000)
     car_6 = Car(3000000, 500000)
     cesar.add_garage(garage_1)
     cesar.add_garage(garage_2)
     cesar.add_garage(garage_3)
     cesar.add_car(car_1, garage_1)
     cesar.add_car(car_2, garage_1)
     cesar.add_car(car_3, garage_2)
     cesar.add_car(car_4, garage_2)
     cesar.add_car(car_5, garage_3)
     cesar.add_car(car_6, garage_3)
     self.assertEqual(cesar.hit_hat(), 3358300)
Ejemplo n.º 10
0
import random
from objects_and_classes.homework.constants import CARS_TYPES, CARS_PRODUCER, TOWNS
from objects_and_classes.homework.homework import Cesar, Garage, Car

c1 = Cesar(name="2131")
c2 = Cesar(name="Naumov")
c3 = Cesar(name="Gavryl")

car1 = Car(price=random.uniform(5000, 50000),
           car_type=random.choice(CARS_TYPES),
           producer=random.choice(CARS_PRODUCER),
           mileage=random.uniform(1000, 5000))
car2 = Car(price=random.uniform(5000, 50000),
           car_type=random.choice(CARS_TYPES),
           producer=random.choice(CARS_PRODUCER),
           mileage=random.uniform(1000, 5000))
car3 = Car(price=random.uniform(5000, 50000),
           car_type=random.choice(CARS_TYPES),
           producer=random.choice(CARS_PRODUCER),
           mileage=random.uniform(1000, 5000))
car4 = Car(price=random.uniform(5000, 50000),
           car_type=random.choice(CARS_TYPES),
           producer=random.choice(CARS_PRODUCER),
           mileage=random.uniform(1000, 5000))
car5 = Car(price=random.uniform(5000, 50000),
           car_type=random.choice(CARS_TYPES),
           producer=random.choice(CARS_PRODUCER),
           mileage=random.uniform(1000, 5000))
car6 = Car(price=random.uniform(5000, 50000),
           car_type=random.choice(CARS_TYPES),
           producer=random.choice(CARS_PRODUCER),