Skip to content

Commit

Permalink
Add model tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Lefkowitz committed Apr 14, 2024
1 parent 42aa4ea commit a89ac6c
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .models.build import Build
from .models.cli import CLI
from .models.flag import Flag
from .models.routine import Routine
from .models.script import Script
from .models.target import Target
from .models.builds.build import Build
from .models.builds.target import Target
from .models.scripts.flag import Flag
from .models.scripts.routine import Routine
from .models.scripts.script import Script
from .models.tasks import Tasks
from .services.compiler import compiler
from .services.environment import inherit
Empty file added src/models/builds/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
Empty file added src/models/scripts/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 13 additions & 9 deletions src/models/cli.py → src/models/tasks.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import sys
from .build import Build
from .flag import Flag
from .routine import Routine
from .script import Script
from .target import Target
from .builds.build import Build
from .scripts.flag import Flag
from .scripts.routine import Routine
from .scripts.script import Script
from .builds.target import Target
from dataclasses import dataclass, field
from SCons.Environment import Environment


@dataclass
class CLI:
class Tasks:
builds: list[Build]

targets: list[Target] = field(default_factory=list)
Expand All @@ -18,15 +18,19 @@ class CLI:
flags: list[Flag] = field(default_factory=list)

def __str__(self) -> str:
return "\n\n".join(
fields = "\n\n".join(
[
":".join([k, "".join([f"\n {i}" for i in v])])
":".join(
[k, "".join([f"\n {i}" for i in v] if len(v) > 0 else "\n -")]
)
for k, v in self.__dict__.items()
]
)

return f"\n{fields}\n"

def dump(self) -> None:
sys.stdout.write(f"{self}\n\n")
sys.stdout.write(f"{self}\n")

def register(self, env: Environment) -> None:
for group in self.__dict__.values():
Expand Down
24 changes: 24 additions & 0 deletions test/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from textwrap import dedent
from src.models.tasks import Tasks
from src.models.builds.build import Build


def test_targets():
assert str(Tasks([Build("main", [])])) == dedent(
"""
builds:
main
targets:
-
scripts:
-
routines:
-
flags:
-
"""
)
7 changes: 6 additions & 1 deletion test/test_tree.py → test/test_services.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from src.services.compiler import compiler
from src.services.environment import inherit


def test_compiler():
assert compiler("c++11", ["all"], ["deprecated-declarations"],) == [
assert compiler("c++11", ["all"], ["deprecated-declarations"]) == [
"-std=c++11",
"-Wall",
"-Wno-deprecated-declarations",
]


def test_environment():
assert "PATH" in inherit()

0 comments on commit a89ac6c

Please sign in to comment.