55import logging
66import os
77import re
8+ import hashlib
89from dataclasses import dataclass , field
910from functools import cached_property
1011from hashlib import sha256
@@ -94,6 +95,11 @@ def make_test_source_with_context(
9495 return TestFile (file_name = file_name , source_dir = source_dir , dest_dir = dest_dir )
9596
9697
98+ def tid_short_hash (tid : str ) -> str :
99+ """Take the first 10 chars of the hash of the given `tid`."""
100+ return hashlib .sha256 (tid .encode ()).hexdigest ()[:10 ]
101+
102+
97103@dataclass (frozen = True )
98104class TestCase :
99105 """A test case is an instance of test definition together with a set of Jinja variables used to render all
@@ -113,8 +119,11 @@ def tid(self) -> str:
113119 """Return the test id. Used as destination folder name for the generated test case.
114120 The result is part of a full directory name of the test case. Therefore, the OS filesystem
115121 directory separator is replaced with underscore.
122+
123+ Since the result is also used as a folder name, we restrict it's length to 255 characters.
124+ This is because some filesystems complain if the name is longer that that.
116125 """
117- return re .sub (
126+ name = re .sub (
118127 f"[{ os .sep } :]" ,
119128 "_" ,
120129 "_" .join (
@@ -124,6 +133,12 @@ def tid(self) -> str:
124133 )
125134 ),
126135 )
136+ max_len = 255
137+ if len (name ) > max_len :
138+ name_hash = tid_short_hash (name )
139+ return f"{ name [: max_len - len (name_hash ) - 1 ]} _{ name_hash } "
140+ else :
141+ return name
127142
128143 def expand (self , template_dir : str , target_dir : str , namespace : str ) -> None :
129144 """Expand test case This will create the target folder, copy files and render render templates."""
0 commit comments