-
Notifications
You must be signed in to change notification settings - Fork 193
Guide to move existing Python2 framework to Python3
This is a basic guide on steps you can follow to move your existing Python2 to Python3 framework.
1. The first step is auto-converting Python2 code to Python3 code. Futurize tool can be used for achieving this. It takes care of import statement changes, syntax changes for print and exception statements. You can follow the below steps to achieve this
a. Install future
pip install future
b. Run futurize after navigating to your current project
futurize --stage1 -w *.py subdir1/*.py subdir2/*.py.
futurize --stage1 -w **/*.py
That was simple. The tool helps to make most of the changes including print, import statements, the way we handle exception statements etc.
2. Replace some files in Page_Objects. Some files in Page_Objects, replace the existing files with the files with Python3 framework. Those files are changed with import statement changes, syntax changes in Print, Exception.
Base_Page.py : iteritems() changed to items()
table_object.py : zip object is changed to list(zip(table_text))[col_index].
3.Under Tests, all tests under Python2 can be replaced with Python3 tests such as test_example_form.py,test_example_table.py,test_mobile_bitcoin_price.py and test_successive_form_creation.py. In these tests, mainly print and exception syntax has been changed.
test_api_example: import and syntax changes taken the case by futurize. API_url is changed, can be copied from Python3 framework.
test_mobile_bitcoin_price.py : Decoding the byte string as string, bitcoin_price_page_heading.decode('utf-8').
4. All util files can be copied from Python3 framework, as the changes are done as per the syntax required for Python3.
5. requirements.txt can be copied directly from Python3 framework. All latest versions are updated there.
6.conftest.py : In conftest.py , mainly import statements are changed according to Python3.
7.For files under Endpoints the changes to be done as below:
Base_Mechanize: Base_Mechanize need to be replaced with Base_API.Python3 does not support Mechanize module, it is replaced with Requests module in Base_API. So Base_Mechanize need to be replaced with Base_API.
API_Interface: Futurize tool take care of Syntax conversions.
API_Player : Methods get_car_count and get_regi_car_count are added to get the initial car count dynamically. Methods need to be copied from API_Player are get_car_count and get_regi_car_count.
In other methods, get_cars, get_car etc, json_response and result_flag is modified according to changes in Base_API. So API_Player can be replaced with API_Player in Python3 Framework.
Cars_API_Endpoints: Import statement need to be changed from Base_Mechanize to Base_API.
All methods like add_car, get_cars,get_car,update_car need to be updated for json_response and return according to with the get,post,put,delete methods in Base_API.
Registration_API_Endpoints: Import statement need to be changed from Base_Mechanize to Base_API.
response and json_response need to be modified under register_car method.
response need to be modified under delete_registered_car.
User_API_Endpoints: Import statement need to be changed from Base_Mechanize to Base_API.
8. All the import functions defined after future import need to be deleted, like from future import absolute_import.