Student Tools · реальный вывод команд темы 02 macOS · Python 3.12.12 · проект во временной папке /tmp/python-book-evidence/student-tools Абсолютные пути на вашем компьютере будут другими. ==================================================================== ГЛАВА 2.1 ==================================================================== student-tools $ python3 --version Python 3.12.12 student-tools $ python3 -m venv .venv (команда завершилась без вывода) student-tools $ ls .venv + cat .venv/pyvenv.cfg bin include lib pyvenv.cfg home = /Users/makarovmn/.pyenv/versions/3.12.12/bin include-system-site-packages = false version = 3.12.12 executable = /Users/makarovmn/.pyenv/versions/3.12.12/bin/python3.12 command = /Users/makarovmn/.pyenv/versions/3.12.12/bin/python3 -m venv /tmp/python-book-evidence/student-tools/.venv (.venv) student-tools $ which python + проверка sys.executable /tmp/python-book-evidence/student-tools/.venv/bin/python Python 3.12.12 /tmp/python-book-evidence/student-tools/.venv/bin/python True (.venv) student-tools $ python -m pip list Package Version ------- ------- pip 25.0.1 ==================================================================== ГЛАВА 2.3 ==================================================================== (.venv) student-tools $ python -c "import rich" Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'rich' (.venv) student-tools $ python -m pip install rich==13.9.4 Collecting rich==13.9.4 Using cached rich-13.9.4-py3-none-any.whl.metadata (18 kB) Collecting markdown-it-py>=2.2.0 (from rich==13.9.4) Downloading markdown_it_py-4.2.0-py3-none-any.whl.metadata (7.4 kB) Collecting pygments<3.0.0,>=2.13.0 (from rich==13.9.4) Using cached pygments-2.21.0-py3-none-any.whl.metadata (2.5 kB) Collecting mdurl~=0.1 (from markdown-it-py>=2.2.0->rich==13.9.4) Using cached mdurl-0.1.2-py3-none-any.whl.metadata (1.6 kB) Using cached rich-13.9.4-py3-none-any.whl (242 kB) Downloading markdown_it_py-4.2.0-py3-none-any.whl (91 kB) Using cached pygments-2.21.0-py3-none-any.whl (1.3 MB) Using cached mdurl-0.1.2-py3-none-any.whl (10.0 kB) Installing collected packages: pygments, mdurl, markdown-it-py, rich Successfully installed markdown-it-py-4.2.0 mdurl-0.1.2 pygments-2.21.0 rich-13.9.4 [notice] A new release of pip is available: 25.0.1 -> 26.2.1 [notice] To update, run: pip install --upgrade pip (.venv) student-tools $ python -m pip show rich Name: rich Version: 13.9.4 Summary: Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal Home-page: https://github.com/Textualize/rich Author: Will McGugan Author-email: willmcgugan@gmail.com License: MIT Location: /tmp/python-book-evidence/student-tools/.venv/lib/python3.12/site-packages Requires: markdown-it-py, pygments Required-by: (.venv) student-tools $ python -m pip --version pip 25.0.1 from /tmp/python-book-evidence/student-tools/.venv/lib/python3.12/site-packages/pip (python 3.12) (.venv) student-tools $ python main.py Средний результат: 4.40 student-tools $ deactivate → which python3 + python3 -m pip show rich /Users/makarovmn/.pyenv/versions/3.12.12/bin/python3 /Users/makarovmn/.pyenv/versions/3.12.12/bin/python3 Name: rich Version: 13.9.4 Summary: Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal Home-page: https://github.com/Textualize/rich Author: Will McGugan Author-email: willmcgugan@gmail.com License: MIT Location: /Users/makarovmn/.pyenv/versions/3.12.12/lib/python3.12/site-packages Requires: markdown-it-py, pygments Required-by: rich-toolkit, typer ==================================================================== ГЛАВА 2.4 · демонстрации теории ==================================================================== student-tools $ python main.py (в файлах есть временный print с __name__) Модуль calculator загружается. __name__ = calculator Модуль main загружается. __name__ = __main__ Средний результат: 4.4 student-tools $ python -c "import main" Модуль calculator загружается. __name__ = calculator Модуль main загружается. __name__ = main student-tools $ python -c "import main_noguard" (копия main.py без условия) Модуль calculator загружается. __name__ = calculator Модуль main загружается. __name__ = main_noguard Средний результат: 4.4 student-tools $ python twice.py (три импорта одного модуля) Модуль calculator загружается. __name__ = calculator calculator в кэше загруженных модулей: True ==================================================================== ГЛАВА 2.5 ==================================================================== (.venv) student-tools $ python app/main.py Traceback (most recent call last): File "/tmp/python-book-evidence/student-tools/app/main.py", line 3, in from app.services.calculator import calculate_average ModuleNotFoundError: No module named 'app' (.venv) student-tools $ python -m app.main Средний результат: 4.40 (.venv) student-tools $ python -c "import app.main" (команда завершилась без вывода) ==================================================================== ГЛАВА 2.5 · демонстрации теории ==================================================================== student-tools $ python -c "from app.services.calculator import calculate_average" (в каждом __init__.py временный print) выполняется app/__init__.py выполняется app/services/__init__.py выполняется app/services/calculator.py импорт закончен, среднее: 4.4 student-tools $ python -c "import app; ..." (папка с __init__.py) __file__: /tmp/python-book-evidence/theory/two/withinit/app/__init__.py __path__: ['/tmp/python-book-evidence/theory/two/withinit/app'] student-tools $ python -c "import app; ..." (та же папка без __init__.py) __file__: None __path__: ['/tmp/python-book-evidence/theory/two/noinit/app'] ==================================================================== ГЛАВА 2.6 ==================================================================== (.venv) student-tools $ python -m pip freeze markdown-it-py==4.2.0 mdurl==0.1.2 Pygments==2.21.0 rich==13.9.4 (.venv) student-tools $ python -m pip freeze > requirements.txt + cat requirements.txt markdown-it-py==4.2.0 mdurl==0.1.2 Pygments==2.21.0 rich==13.9.4 (.venv) student-tools $ python -m unittest discover -s tests -v test_average (test_calculator.AverageTests.test_average) ... ok test_empty (test_calculator.AverageTests.test_empty) ... ok test_format (test_calculator.AverageTests.test_format) ... ok ---------------------------------------------------------------------- Ran 3 tests in 0.000s OK ==================================================================== ГЛАВА 2.6 · демонстрации теории ==================================================================== student-tools $ python -c "print(0.1 + 0.2); print(0.1 + 0.2 == 0.3); print(sum([5,4,5,3,5]) / 5)" 0.30000000000000004 False 4.4 (.venv) student-tools $ тесты при ошибке в формуле расчёта test_average (test_calculator.AverageTests.test_average) ... FAIL test_empty (test_calculator.AverageTests.test_empty) ... ok test_format (test_calculator.AverageTests.test_format) ... ok ====================================================================== FAIL: test_average (test_calculator.AverageTests.test_average) ---------------------------------------------------------------------- Traceback (most recent call last): File "/tmp/python-book-evidence/tests-demo/tests/test_calculator.py", line 8, in test_average self.assertAlmostEqual(calculate_average([5, 4, 5, 3, 5]), 4.4) AssertionError: 5.5 != 4.4 within 7 places (1.0999999999999996 difference) ---------------------------------------------------------------------- Ran 3 tests in 0.000s FAILED (failures=1) (.venv) student-tools $ тесты при неверном вызове функции в самом тесте test_average (test_calculator.AverageTests.test_average) ... ERROR test_empty (test_calculator.AverageTests.test_empty) ... ok test_format (test_calculator.AverageTests.test_format) ... ok ====================================================================== ERROR: test_average (test_calculator.AverageTests.test_average) ---------------------------------------------------------------------- Traceback (most recent call last): File "/tmp/python-book-evidence/tests-demo/tests/test_calculator.py", line 8, in test_average self.assertAlmostEqual(calculate_average(5, 4, 5, 3, 5), 4.4) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: calculate_average() takes 1 positional argument but 5 were given ---------------------------------------------------------------------- Ran 3 tests in 0.000s FAILED (errors=1) (.venv) student-tools $ тесты, когда файл назван не с test_ ---------------------------------------------------------------------- Ran 0 tests in 0.000s NO TESTS RAN ==================================================================== ГЛАВА 2.6 ==================================================================== student-tools $ чистая папка: ls -a . .. .gitignore app requirements.txt tests student-tools $ python3 -m venv .venv (команда завершилась без вывода) (.venv) student-tools $ python -m pip install -r requirements.txt Collecting markdown-it-py==4.2.0 (from -r requirements.txt (line 1)) Using cached markdown_it_py-4.2.0-py3-none-any.whl.metadata (7.4 kB) Collecting mdurl==0.1.2 (from -r requirements.txt (line 2)) Using cached mdurl-0.1.2-py3-none-any.whl.metadata (1.6 kB) Collecting Pygments==2.21.0 (from -r requirements.txt (line 3)) Using cached pygments-2.21.0-py3-none-any.whl.metadata (2.5 kB) Collecting rich==13.9.4 (from -r requirements.txt (line 4)) Using cached rich-13.9.4-py3-none-any.whl.metadata (18 kB) Using cached markdown_it_py-4.2.0-py3-none-any.whl (91 kB) Using cached mdurl-0.1.2-py3-none-any.whl (10.0 kB) Using cached pygments-2.21.0-py3-none-any.whl (1.3 MB) Using cached rich-13.9.4-py3-none-any.whl (242 kB) Installing collected packages: Pygments, mdurl, markdown-it-py, rich Successfully installed Pygments-2.21.0 markdown-it-py-4.2.0 mdurl-0.1.2 rich-13.9.4 [notice] A new release of pip is available: 25.0.1 -> 26.2.1 [notice] To update, run: pip install --upgrade pip (.venv) student-tools $ python -m app.main + python -m unittest discover -s tests -v Средний результат: 4.40 test_average (test_calculator.AverageTests.test_average) ... ok test_empty (test_calculator.AverageTests.test_empty) ... ok test_format (test_calculator.AverageTests.test_format) ... ok ---------------------------------------------------------------------- Ran 3 tests in 0.000s OK