Skip to content

Commit b3e18c1

Browse files
committed
chore: Update flake8 max line length to 200
1 parent 449b204 commit b3e18c1

6 files changed

Lines changed: 30 additions & 9 deletions

File tree

.github/workflows/test-script.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
pip install -r requirements.dev.txt
3131
3232
- name: Lint with flake8
33-
run: flake8 --max-line-length=88 .
33+
run: flake8 --max-line-length=200 .
3434
continue-on-error: true
3535

3636
- name: Run tests

struct_module/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
from .main import *
2-
from .utils import *
3-
from .file_item import *
1+
# Struct Module

struct_module/file_item.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
openai_api_key = os.getenv("OPENAI_API_KEY")
1313
openai_model = os.getenv("OPENAI_MODEL")
1414

15+
1516
class FileItem:
1617
def __init__(self, properties):
1718
self.name = properties.get("name")

struct_module/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
if not openai_api_key:
1313
logging.warning("OpenAI API key not found. Skipping processing prompt.")
1414

15+
1516
def main():
1617
import argparse
1718

@@ -66,5 +67,6 @@ def main():
6667

6768
logging.info("Finished creating project structure")
6869

70+
6971
if __name__ == "__main__":
7072
main()

struct_module/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
openai_api_key = os.getenv("OPENAI_API_KEY")
1010
openai_model = os.getenv("OPENAI_MODEL")
1111

12+
1213
def validate_configuration(structure):
1314
if not isinstance(structure, list):
1415
raise ValueError("The 'structure' key must be a list.")
@@ -38,6 +39,7 @@ def validate_configuration(structure):
3839
raise ValueError(f"The content of '{name}' must be a string or dictionary.")
3940
logging.info("Configuration validation passed.")
4041

42+
4143
def create_structure(base_path, structure, dry_run=False, template_vars=None, backup_path=None, file_strategy='overwrite', global_system_prompt=None):
4244
for item in structure:
4345
logging.debug(f"Processing item: {item}")
@@ -55,10 +57,12 @@ def create_structure(base_path, structure, dry_run=False, template_vars=None, ba
5557
file_item.process_prompt(dry_run)
5658
file_item.create(base_path, dry_run, backup_path, file_strategy)
5759

60+
5861
def read_config_file(file_path):
5962
with open(file_path, 'r') as f:
6063
return yaml.safe_load(f)
6164

65+
6266
def merge_configs(file_config, args):
6367
args_dict = vars(args)
6468
for key, value in file_config.items():

tests/test_script.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
import tempfile
44
import time
55
import logging
6-
from unittest.mock import patch, MagicMock
6+
from unittest.mock import patch
77
from struct_module.utils import FileItem, validate_configuration, create_structure
88

9+
910
# Mock the environment variables for OpenAI
1011
@pytest.fixture(autouse=True)
1112
def mock_env_vars(monkeypatch):
1213
monkeypatch.setenv("OPENAI_API_KEY", "test-api-key")
1314
monkeypatch.setenv("OPENAI_MODEL", "gpt-3.5-turbo")
1415

16+
1517
# Test for FileItem.fetch_content
16-
@patch('struct_module.requests.get')
18+
@patch('struct_module.file_item.requests.get')
1719
def test_fetch_remote_content(mock_get):
1820
mock_get.return_value.status_code = 200
1921
mock_get.return_value.text = "Mocked content"
@@ -24,6 +26,7 @@ def test_fetch_remote_content(mock_get):
2426
assert file_item.content == "Mocked content"
2527
mock_get.assert_called_once_with("https://example.com/mock")
2628

29+
2730
# Test for FileItem.apply_template_variables
2831
def test_apply_template_variables():
2932
file_item = FileItem({"name": "README.md", "content": "Hello, ${name}!"})
@@ -33,6 +36,7 @@ def test_apply_template_variables():
3336

3437
assert file_item.content == "Hello, World!"
3538

39+
3640
# Test for validate_configuration
3741
def test_validate_configuration():
3842
valid_structure = [
@@ -55,6 +59,7 @@ def test_validate_configuration():
5559
with pytest.raises(ValueError):
5660
validate_configuration(invalid_structure)
5761

62+
5863
# Test for FileItem.create with different strategies
5964
def test_create_file():
6065
structure = [
@@ -87,6 +92,7 @@ def test_create_file():
8792
assert f.read() == "#!/bin/bash\necho 'Hello, World!'"
8893
assert oct(os.stat(script_path).st_mode)[-3:] == '777'
8994

95+
9096
# Test for dry run
9197
def test_dry_run(caplog):
9298
structure = [
@@ -102,10 +108,12 @@ def test_dry_run(caplog):
102108
create_structure(tmpdirname, structure, dry_run=True)
103109

104110
assert not os.path.exists(os.path.join(tmpdirname, "README.md"))
105-
assert any("[DRY RUN] Would create file:" in message for message in caplog.messages)
111+
assert any("[DRY RUN] Would create file:" in message
112+
for message in caplog.messages)
113+
106114

107115
# Mocking requests.get for testing fetch_remote_content within create_structure
108-
@patch('struct_module.requests.get')
116+
@patch('struct_module.file_item.requests.get')
109117
def test_create_structure_with_remote_content(mock_get):
110118
mock_get.return_value.status_code = 200
111119
mock_get.return_value.text = "Remote content"
@@ -126,6 +134,7 @@ def test_create_structure_with_remote_content(mock_get):
126134
with open(license_path, 'r') as f:
127135
assert f.read() == "Remote content"
128136

137+
129138
# Test for backup strategy
130139
def test_backup_strategy():
131140
structure = [
@@ -144,12 +153,16 @@ def test_backup_strategy():
144153
backup_path = os.path.join(tmpdirname, "backup")
145154
os.makedirs(backup_path)
146155

147-
create_structure(tmpdirname, structure, backup_path=backup_path, file_strategy='backup')
156+
create_structure(tmpdirname,
157+
structure,
158+
backup_path=backup_path,
159+
file_strategy='backup')
148160

149161
assert os.path.exists(os.path.join(backup_path, "README.md"))
150162
with open(readme_path, 'r') as f:
151163
assert f.read() == "This is a README file."
152164

165+
153166
# Test for skip strategy
154167
def test_skip_strategy():
155168
structure = [
@@ -170,6 +183,7 @@ def test_skip_strategy():
170183
with open(readme_path, 'r') as f:
171184
assert f.read() == "Existing content"
172185

186+
173187
# Test for append strategy
174188
def test_append_strategy():
175189
structure = [
@@ -190,6 +204,7 @@ def test_append_strategy():
190204
with open(readme_path, 'r') as f:
191205
assert f.read() == "Existing content. Appended content."
192206

207+
193208
# Test for rename strategy
194209
def test_rename_strategy():
195210
structure = [
@@ -212,6 +227,7 @@ def test_rename_strategy():
212227
with open(readme_path, 'r') as f:
213228
assert f.read() == "This is a new README file."
214229

230+
215231
# Test for directory creation
216232
def test_create_structure_creates_directory():
217233
structure = [

0 commit comments

Comments
 (0)