Git Product home page Git Product logo

html-converter-kata's Introduction

๐Ÿ“„ HTML Converter Kata ๐Ÿ“„

Python

Resources

These instructions where extracted from Emily Bache repository. The link to the original repository can be found in the link bellow.

Web

Description

This kata is part of the Racing Kart Kata series, which is a set of exercises to practice TDD and SOLID principles.

There are several variants of this exercise in this repo. They all present slightly different challenges. You can expect to learn more about test design, SOLID principles and testability by working on them.

As a first step, try to get some kind of test in place before you change the class at all. If the tests are hard to write, is that because of the problems with SOLID principles?

When you have some kind of test to lean on, refactor the code and make it testable. Take care when refactoring not to alter the functionality, or change interfaces which other client code may rely on. Add more tests to cover the functionality of the particular class you've been asked to get under test.

UnicodeFileToHtmlTextConverter

Write the unit tests for the UnicodeFileToHtmlTextConverter class. This class is designed to reformat a plain text file for display in a browser.

Bonus: identify which of the SOLID principles this code violates.

HtmlPagesConverter

Write the unit tests for the HtmlPagesConverter class. This class is designed to reformat a plain text file for display in a browser, one page at a time.

HtmlConverter

Write unit tests that expose the bugs. Bugs are marked with a comment in the code. You should preserve the original interface to the class.

Objective

The objective of the kata is to identify the SOLID principle that is not being followed and refactor the code to make it testable and maintainable.

We will learn how to work with legacy code that is difficult to test and learn how to refactor step by step. We can use Mocks, Stubs or none at all to test the code.

Configuration

The project can be configured with poetry and pyenv.

  1. Install python version with pyenv:

    pyenv install 3.12.0
  2. Install poetry:

    pip install poetry
  3. Create a virtual environment and install dependencies:

    poetry install
    poetry install --dev

    By default, it will create the virtual environment outside the project. To create it inside, use the following command:

    poetry config virtualenvs.in-project true
    poetry install
  4. Activate the virtual environment:

     poetry shell

    You can activate it manually running source .venv/bin/activate on Unix systems or source .venv/Scripts/activate on Windows.

Running the tests

To run the tests, execute one of the following commands:

pytest

or

poetry run pytest

Learnings

UnicodeFileToHtmlTextConverter

  • The Single Responsibility principle was not being followed. The class was responsible for reading a file and converting it to HTML, it had more than one reason to change.
  • We've learned how to use Approval Tests to be able to refactor the code in safe steps without being completely sure of the behavior of the class.
  • We've used Mocks to test the behavior of the class decoupled from the file system once we've refactored

Visit my GitHub profile to see all solved katas ๐Ÿš€

Web

html-converter-kata's People

Contributors

dimanu-py avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.