Skip to content

Commit

Permalink
REFACTOR:
Browse files Browse the repository at this point in the history
- Added test to check HTML generated file existence
- Restructured the tool
- Updated unit-tests
- Renamed the tool, updated README.md
- Updated CONTRIBUTING.md page
  • Loading branch information
abatomunkuev committed Nov 27, 2021
1 parent fa10ee5 commit c864dad
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 26 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to Static Site Generator
# Contributing to Fast Static Site Generator

Welcome to the Contribution Page! This page provides useful information about contributing to the tool

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Static Site Generator SSG
Static Site Generator (SSG) - a tool for generating a complete HTML files from raw data like txt and md files. This tool was made with Python language.
# Fast Static Site Generator
Fast Static Site Generator (Fast SSG) - a tool for generating a complete HTML files from raw data like txt and md files. This tool was made with Python language.

## Prerequisites
- Python3
Expand Down Expand Up @@ -27,11 +27,11 @@ pip3 install -r requirements.txt
## Usage with shorthand flags
| Description | Command |
| ------------ | -------- |
|Generate basic HTML file(s)|`python3 ssg.py --input "relative path or absolute path to the file or folder"`|
|Generate basic HTML file(s) with CSS stylesheet | `python3 ssg.py --input "relative path or absolute path to the file or folder" --stylesheet "URL to CSS stylesheet"`|
|New Feature: Support arguments passed with Config File | `python3 ssg.py -c ./ssg-config.json` |
|Help | `python3 ssg.py --help` |
|Get current version | `python3 ssg.py --version`|
|Generate basic HTML file(s)|`python3 fast_ssg --input "relative path or absolute path to the file or folder"`|
|Generate basic HTML file(s) with CSS stylesheet | `python3 fast_ssg --input "relative path or absolute path to the file or folder" --stylesheet "URL to CSS stylesheet"`|
|New Feature: Support arguments passed with Config File | `python3 fast_ssg -c ./ssg-config.json` |
|Help | `python3 fast_ssg --help` |
|Get current version | `python3 fast_ssg --version`|

## Shorthand flags
| Flag | Shorthand version |
Expand Down
4 changes: 4 additions & 0 deletions fast_ssg/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os
import sys

sys.path.append(os.path.dirname(os.path.realpath(__file__)))
8 changes: 2 additions & 6 deletions ssg.py → fast_ssg/__main__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
"""
This code is a main file
"""
import os
import shutil
from ssg import TextFile
from ssg import OUTPUT_DIR
from ssg import cla_parser, determine_path, generate_index_html
from text import OUTPUT_DIR, TextFile
from utils import cla_parser, determine_path, generate_index_html


def main():
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions ssg/utils.py → fast_ssg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from io import open
import argparse
import os
from ssg.text import OUTPUT_DIR
from text import OUTPUT_DIR


def generate_index_html(stylesheet, links):
Expand Down Expand Up @@ -105,7 +105,7 @@ def cla_parser():
# https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser
parser = argparse.ArgumentParser(
description=(
"""Static Site Generator - is a tool to generate
"""Fast Static Site Generator - is a tool to generate
HTML files from raw data like txt files."""
)
)
Expand All @@ -121,7 +121,7 @@ def cla_parser():
"-v",
"--version",
action="version",
version="Static Site Generator 0.1",
version="Fast Static Site Generator 0.1",
help="show program's version number and exit",
)
# --stylesheet -s argument
Expand Down
3 changes: 0 additions & 3 deletions ssg/__init__.py

This file was deleted.

3 changes: 2 additions & 1 deletion tests/text_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import shutil
import pytest
from ssg import TextFile, determine_path, OUTPUT_DIR
from fast_ssg.utils import determine_path
from fast_ssg.text import OUTPUT_DIR, TextFile


class TestText:
Expand Down
39 changes: 34 additions & 5 deletions tests/utils_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from ssg import determine_path
import pytest
import subprocess
import os
import sys
from fast_ssg.utils import determine_path


class TestUtils:
Expand Down Expand Up @@ -54,18 +56,20 @@ def test_cla_parser_version_arg(self):
"""
# Check short-cut -v
shortcut_version_output = subprocess.check_output(
"python3 -c 'from ssg import cla_parser; cla_parser()' -v", shell=True
"python3 -c 'from fast_ssg.utils import cla_parser; cla_parser()' -v",
shell=True,
)
assert (
shortcut_version_output.decode("utf-8") == "Static Site Generator 0.1\n"
shortcut_version_output.decode("utf-8")
== "Fast Static Site Generator 0.1\n"
), 'Should output "Static Site Generator 0.1"'
# Check full argument --version
full_version_output = subprocess.check_output(
"python3 -c 'from ssg import cla_parser; cla_parser()' --version",
"python3 -c 'from fast_ssg.utils import cla_parser; cla_parser()' --version",
shell=True,
)
assert (
full_version_output.decode("utf-8") == "Static Site Generator 0.1\n"
full_version_output.decode("utf-8") == "Fast Static Site Generator 0.1\n"
), 'Should output "Static Site Generator 0.1"'

def test_cla_parser_invalid_input_arg(self):
Expand All @@ -75,3 +79,28 @@ def test_cla_parser_invalid_input_arg(self):
# Should throw error
with pytest.raises(Exception):
subprocess.check_output("python3 ssg.py -i ../../invalid_path", shell=True)

def test_html_files_built(self):
"""
Test case to test the existence of generated HTML files
This case will use the files from test_files directory.
"""
# Run the tool passing the test_files directory
subprocess.run([sys.executable, "ssg.py", "-i", "./tests/test_files/"])
test_files = []
# Checking if the generated files exists
for file in os.listdir("./tests/test_files"):
if file.endswith(".txt") or file.endswith(".md"):
test_files.append(
"_".join(
[str.lower(name) for name in file.split(".")[0].split(" ")]
)
+ ".html"
)
assert os.path.isdir("./dist"), "dist/ directory should exist"
if os.path.isdir("./dist"):
# Check if the files above exists in dist directory
for html_file in os.listdir("./dist"):
assert (
html_file in test_files
), "HTML file should be the same as in the test dir"

0 comments on commit c864dad

Please sign in to comment.