Verify_HelloWorld/llm-artifacts/02-writer.md

2.3 KiB
Raw Blame History

План приложения helloworld

Структура проекта

helloworld/
├── src/
│   └── main.py
├── tests/
│   └── test_main.py
├── .gitignore
├── README.md
└── requirements.txt

Файлы

  1. src/main.py

    def say_hello():
        return "Hello, World!"
    
    if __name__ == "__main__":
        print(say_hello())
    
  2. 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()
    
  3. .gitignore

    /tests/__pycache__/
    
  4. README.md

    # helloworld
    Простое приложение на Python, выводящее "Hello, World!".
    
  5. requirements.txt

    # No external dependencies required
    

Шаги сборки

  1. Создайте новый каталог для проекта helloworld.
  2. Создайте файл src/main.py и вставьте в него код:
    def say_hello():
        return "Hello, World!"
    
    if __name__ == "__main__":
        print(say_hello())
    
  3. Создайте каталог 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()
    
  4. Создайте файл .gitignore с содержимым:
    /tests/__pycache__/
    
  5. Создайте файл README.md с содержимым:
    # helloworld
    Простое приложение на Python, выводящее "Hello, World!".
    
  6. Создайте файл requirements.txt и оставьте его пустым, так как нет внешних зависимостей.
  7. В терминале перейдите в каталог helloworld и выполните команду python -m unittest tests/test_main.py для запуска тестов.
  8. Если тесты прошли успешно, приложение готово к использованию.