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

Python translation #61

Merged
merged 27 commits into from
Mar 12, 2023
Merged

Python translation #61

merged 27 commits into from
Mar 12, 2023

Conversation

emilybache
Copy link
Contributor

The translation is based on the typescript version. The github action runs the tests.

on:
push:
paths:
- 'python/**'

Choose a reason for hiding this comment

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

😎

- name: Checkout Repository
uses: actions/checkout@v2

- name: Start MYSQL and import DB

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part is just copied from the typescript version. Should probably update all the versions together?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would leave that for a separate PR

Choose a reason for hiding this comment

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

(15, 35, datetime.fromisoformat('2019-02-22')),
(15, 35, datetime.fromisoformat('2019-02-25')), # monday, holiday
(15, 23, datetime.fromisoformat('2019-03-11')), # monday
(65, 18, datetime.fromisoformat('2019-03-11')), # monday

Choose a reason for hiding this comment

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

did you use a coverage / mutation tool?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no I just translated the typescript tests.

sudo systemctl start mysql
mysqladmin --user=${{ env.DB_USER }} --password=${{ env.DB_OLD_PASSWORD }} version
mysqladmin --user=${{ env.DB_USER }} --password=${{ env.DB_OLD_PASSWORD }} password ${{ env.DB_PASSWORD }}
mysql -u${{ env.DB_USER }} -p${{ env.DB_PASSWORD }} < ${GITHUB_WORKSPACE}/database/initDatabase.sql

Choose a reason for hiding this comment

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

like 👍🏼

mysqladmin --user=${{ env.DB_USER }} --password=${{ env.DB_OLD_PASSWORD }} password ${{ env.DB_PASSWORD }}
mysql -u${{ env.DB_USER }} -p${{ env.DB_PASSWORD }} < ${GITHUB_WORKSPACE}/database/initDatabase.sql

- name: Install MySQL odbc driver

Choose a reason for hiding this comment

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

🤔 other translations don't rely on odbc, is it a must?

Choose a reason for hiding this comment

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

I've experimented with this alternative:
emilybache#1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used odbc because it makes it easier to switch to a different database. It's probably not necessary here though as you point out

@codecop
Copy link
Collaborator

codecop commented Mar 4, 2023

Emily, thank you for the translation. Looks very good. There is a small inconsistency to the other projects - because also typescript version has it.

  1. There is a main entry point (class, whatever) which calls createApp and then gets the connection and the application. It will print a message with a test URL and proper port (look into index.ts in the Typescript) and then starts the app by listening. So please instead of having the run of app in the main method of Prices, please create a separate file.

  2. The createApp is also returning the connection, so tests can close it after running. I do not see the tests closing the connection, maybe a method provided to shutdown of process? I think it's OK to get the values app and importing by running the module like it is now, connection is just available globally then?

@codecop
Copy link
Collaborator

codecop commented Mar 4, 2023

  1. I am missing the Readme that all other languages have. That should be little work, just copy any Readme and change links and commands to run the tests and application.

@nitsanavni
Copy link

I do not see the tests closing the connection

that's because the test is spawning the app as a child process, and once the child process is terminated it stops connections (at least, I believe it does)

@martinsson
Copy link
Owner

martinsson commented Mar 5, 2023

Thanks @emilybache !

I tried to run this version on a macbook

The slight problem is I need to adapt the install of mysql-odbc. I think @nitsanavni suggestion solves that problem. Probably also for windows. However it's not complete (still some references to pyodbc).

I'd suggest

  • add the readme with the setup suggested by @codecop, I did the following (based on your github workflow)
python3 -m venv venv
. venv/bin/activate
pip3 install -r requirements.txt
PYTHONPATH=src python3 -m pytest
  • merge as-is noting that the setup is for linux

As a second step finalize @nitsanavni's contribution to make it platform independent.

@emilybache
Copy link
Contributor Author

Thankyou for all your comments! I feel a bit embarrassed I forgot the readme file, sorry about that. I'll fix that and look at your other comments soon.

@codecop
Copy link
Collaborator

codecop commented Mar 6, 2023

No I feel embarrassed to ask you for changes.

@emilybache
Copy link
Contributor Author

To answer the points from @codecop

  1. I wasn't able to work out how to put the Flask application creation in a different file from the methods with the app.route decoration. It might be possible but I don't know how. Sorry!
  2. The db connection is not being explicitly closed, but it should close automatically when you kill the process. I don't think it's important to do explicitly. It is important that it's created in the same thread where it's used, and i fixed that at least.
  3. I added a README which I hope does the job.

@martinsson
Copy link
Owner

OK Great @emilybache ! this works on a macbook too using the normal dependency of docker.

Nice try with sql lite as well although it fails at ON DUPLICATE KEY UPDATE cost = ?. I don't know how to solve this, other than going all the way to an ORM like sqlalchemy. This was actually the approach taken by https://github.com/martinsson/Refactoring-Kata-Lift-Pass-Pricing/pull/58/files. A MR I never got around to merge. I don't know what to do with it now though. It could be merged as a way of having sqllite. But If anyone has another idea of how to add the sqllite functionality to this project that'd be preferable.

Out of the suggestions you made nitsanavni. Is there any improvement you see still? Please to Provide a PR if so ! 👍

@martinsson martinsson merged commit 57cfc5d into martinsson:with_tests Mar 12, 2023
@martinsson
Copy link
Owner

@emilybache FYI. I rewrote the test branch to alway keep the master branch mergeable into the with-tests branch. It's a convention that is useful when we make some modification to the master branche.
It still looks like your commit as I authored it in your name. Ping me if you're not ok with that.

@emilybache
Copy link
Contributor Author

Hi,

Thanks Johan for fixing the git history so master can be merged into with_tests. I guess I was doing too much cherry-picking or something.

As for the sqlite thing - I have this branch in my repo with a version of the production code that also works with sqlite: https://github.com/emilybache/Refactoring-Kata-Lift-Pass-Pricing/blob/with_tests_sqlite3/python/src/prices.py it's even more horrible than the original and of course doesn't match the other language versions. It is platform independent though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants