2.3 KiB
2.3 KiB
План приложения helloworld
Структура проекта
helloworld/
├── src/
│ └── main.py
├── tests/
│ └── test_main.py
├── .gitignore
├── README.md
└── requirements.txt
Файлы
-
src/main.py
def say_hello(): return "Hello, World!" if __name__ == "__main__": print(say_hello()) -
tests/test_main.py
import unittest from src.main import say_hello class TestMain(unittest.TestCase): def test_say_hello(self): self.assertEqual(say_hello(), "Hello, World!") if __name__ == "__main__": unittest.main() -
.gitignore
/tests/__pycache__/ -
README.md
# helloworld Простое приложение на Python, выводящее "Hello, World!". -
requirements.txt
# No external dependencies required
Шаги сборки
- Создайте новый каталог для проекта
helloworld. - Создайте файл
src/main.pyи вставьте в него код:def say_hello(): return "Hello, World!" if __name__ == "__main__": print(say_hello()) - Создайте каталог
testsи файлtests/test_main.pyс кодом:import unittest from src.main import say_hello class TestMain(unittest.TestCase): def test_say_hello(self): self.assertEqual(say_hello(), "Hello, World!") if __name__ == "__main__": unittest.main() - Создайте файл
.gitignoreс содержимым:/tests/__pycache__/ - Создайте файл
README.mdс содержимым:# helloworld Простое приложение на Python, выводящее "Hello, World!". - Создайте файл
requirements.txtи оставьте его пустым, так как нет внешних зависимостей. - В терминале перейдите в каталог
helloworldи выполните командуpython -m unittest tests/test_main.pyдля запуска тестов. - Если тесты прошли успешно, приложение готово к использованию.