Set up ability to run commands from the terminal
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
from tungston.core.world import World
|
||||
from tungston.generator.markdown.report import Report
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class BiomeReport(Report):
|
||||
|
||||
def __init__(self, world:World):
|
||||
super().__init__("biomes.md", world)
|
||||
|
||||
def build(self):
|
||||
for biome in self.world.biomes.all():
|
||||
self.line(f"# Biome: {biome.city} <{biome.gameId}>")
|
||||
self.line()
|
||||
|
||||
self.indent()
|
||||
for trait in biome.traits():
|
||||
self.text("* ").line(trait)
|
||||
self.outdent()
|
||||
|
||||
self.line()
|
||||
@@ -0,0 +1,61 @@
|
||||
from pytest import fixture
|
||||
from tungston.core.ecology.biome import Biome
|
||||
from tungston.core.ecology.biomecatalog import BiomeCatalog
|
||||
from tungston.core.world import World
|
||||
from tungston.generator.markdown.biomereport import BiomeReport
|
||||
|
||||
import tungston.core.ecology.flora as F
|
||||
import tungston.core.ecology.geology as G
|
||||
import tungston.core.ecology.heat as E
|
||||
import tungston.core.ecology.humidity as U
|
||||
import tungston.core.ecology.soil as S
|
||||
import tungston.core.ecology.water as W
|
||||
|
||||
import textwrap
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="biomes")
|
||||
def createCatalog():
|
||||
yield BiomeCatalog([
|
||||
Biome("dallas", "minecraft:savanna",
|
||||
F.FIELD, G.SEDIMENTARY, E.SUBTROPICAL, U.DRY, S.SANDY, W.INLAND
|
||||
),
|
||||
Biome("kansascity", "minecraft:plains",
|
||||
F.FIELD, G.SEDIMENTARY, E.TEMPERATE, U.DAMP, S.LOAMY, W.INLAND
|
||||
),
|
||||
])
|
||||
|
||||
@fixture(name="world")
|
||||
def createWorld(biomes):
|
||||
yield World(biomes, None, None, None)
|
||||
|
||||
@fixture(name="report")
|
||||
def createReport(world):
|
||||
report = BiomeReport(world)
|
||||
report.build()
|
||||
yield report
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_report(report):
|
||||
assert str(report) == textwrap.dedent("""
|
||||
# Biome: dallas <minecraft:savanna>
|
||||
|
||||
* Flora: field
|
||||
* Geology: sedimentary
|
||||
* Heat: subtropical
|
||||
* Humidity: dry
|
||||
* Soil: sandy
|
||||
* Water: inland
|
||||
|
||||
# Biome: kansascity <minecraft:plains>
|
||||
|
||||
* Flora: field
|
||||
* Geology: sedimentary
|
||||
* Heat: temperate
|
||||
* Humidity: damp
|
||||
* Soil: loamy
|
||||
* Water: inland
|
||||
""").strip()
|
||||
@@ -6,6 +6,9 @@ from tungston.generator.markdown.report import Report
|
||||
|
||||
class MineralReport(Report):
|
||||
|
||||
def __init__(self, world:World):
|
||||
super().__init__("minerals.md", world)
|
||||
|
||||
def build(self):
|
||||
for mineral in self.world.minerals.all():
|
||||
self.line(f"# Mineral: {mineral.name}")
|
||||
@@ -13,7 +16,7 @@ class MineralReport(Report):
|
||||
|
||||
self.indent()
|
||||
for replacement in mineral.replacements:
|
||||
self.line(str(replacement))
|
||||
self.text("* ").line(str(replacement))
|
||||
self.outdent()
|
||||
|
||||
self.line()
|
||||
|
||||
@@ -45,11 +45,11 @@ def test_report(report):
|
||||
assert str(report) == textwrap.dedent("""
|
||||
# Mineral: copper
|
||||
|
||||
#minecraft:stone_replaceables => minecraft:copper_ore
|
||||
#minecraft:deepslate_replaceables => minecraft:deepslate_copper_ore
|
||||
* #minecraft:stone_replaceables => minecraft:copper_ore
|
||||
* #minecraft:deepslate_replaceables => minecraft:deepslate_copper_ore
|
||||
|
||||
# Mineral: iron
|
||||
|
||||
#minecraft:stone_replaceables => minecraft:iron_ore
|
||||
#minecraft:deepslate_replaceables => minecraft:deepslate_iron_ore
|
||||
* #minecraft:stone_replaceables => minecraft:iron_ore
|
||||
* #minecraft:deepslate_replaceables => minecraft:deepslate_iron_ore
|
||||
""").strip()
|
||||
|
||||
@@ -4,13 +4,14 @@ from tungston.core.world import World
|
||||
|
||||
# Constants ########################################################################################
|
||||
|
||||
INDENT = " "
|
||||
INDENT = " "
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class Report:
|
||||
|
||||
def __init__(self, world:World):
|
||||
def __init__(self, name:str, world:World):
|
||||
self.name = name
|
||||
self.world = world
|
||||
self.reset()
|
||||
|
||||
|
||||
@@ -4,14 +4,10 @@ from tungston.generator.markdown.report import Report
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="emptyReport")
|
||||
def createEmptyReport():
|
||||
return Report()
|
||||
|
||||
@fixture(name="report")
|
||||
def createReport():
|
||||
return (
|
||||
Report(None)
|
||||
Report("test", None)
|
||||
.text("alpha")
|
||||
.line("bravo")
|
||||
.indent()
|
||||
@@ -28,4 +24,4 @@ def test_repr(report):
|
||||
assert repr(report) == "Report{lines: 4 lines, lineBuffer: 1 chunks, indent: 1}"
|
||||
|
||||
def test_str(report):
|
||||
assert str(report) == "alphabravo\n charlie\n delta\n echo"
|
||||
assert str(report) == "alphabravo\n charlie\n delta\n echo"
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
from tungston.generator.markdown.report import Report
|
||||
|
||||
import shutil
|
||||
import os
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class ReportWriter:
|
||||
|
||||
def __init__(self, reports:list[Report]):
|
||||
self._reports = reports
|
||||
|
||||
def write(self, reportDirPath:str):
|
||||
if os.path.exists(reportDirPath):
|
||||
shutil.rmtree(reportDirPath)
|
||||
|
||||
os.makedirs(reportDirPath, exist_ok=True)
|
||||
|
||||
for report in self._reports:
|
||||
report.build()
|
||||
|
||||
path = os.path.join(reportDirPath, report.name)
|
||||
with open(path, "w") as file:
|
||||
file.write(str(report))
|
||||
Reference in New Issue
Block a user