mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-14 03:37:55 -04:00
88090ec73a
Co-authored-by: James Gilles <jameshgilles@gmail.com>
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from .. import Smoketest, random_string
|
|
import tempfile
|
|
import os
|
|
from glob import iglob
|
|
|
|
|
|
def count_matches(dir, needle):
|
|
count = 0
|
|
for f in iglob(os.path.join(dir, "**/*.cs"), recursive=True):
|
|
with open(f) as f:
|
|
count += f.read().count(needle)
|
|
return count
|
|
|
|
|
|
class Namespaces(Smoketest):
|
|
AUTOPUBLISH = False
|
|
|
|
def test_spacetimedb_ns_csharp(self):
|
|
"""Ensure that the default namespace is working properly"""
|
|
|
|
namespace = "SpacetimeDB.Types"
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
self.spacetime("generate", "--out-dir", tmpdir, "--lang=cs", "--project-path", self.project_path)
|
|
|
|
self.assertEqual(count_matches(tmpdir, f"namespace {namespace}"), 7)
|
|
self.assertEqual(count_matches(tmpdir, "using SpacetimeDB;"), 0)
|
|
|
|
def test_custom_ns_csharp(self):
|
|
"""Ensure that when a custom namespace is specified on the command line, it actually gets used in generation"""
|
|
|
|
namespace = random_string()
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
self.spacetime("generate", "--out-dir", tmpdir, "--lang=cs", "--namespace", namespace, "--project-path", self.project_path)
|
|
|
|
self.assertEqual(count_matches(tmpdir, f"namespace {namespace}"), 7)
|
|
self.assertEqual(count_matches(tmpdir, "using SpacetimeDB;"), 7)
|