Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ jobs:
run: |
cmake -B build -G Ninja -S runtime -DBUILD_TESTING=ON
cmake --build build --parallel
- uses: actions/setup-python@v5
if: matrix.os == 'ubuntu-latest'
with:
python-version: '3.x'
- name: Install dependencies & Generate TN models
if: matrix.os == 'ubuntu-latest'
run: |
pip install pynini importlib_resources
python -m tn --language zh --overwrite_cache
- name: Run tests
if: matrix.os == 'ubuntu-latest'
run: ctest --test-dir build/test --output-on-failure

build-windows:
name: build (windows-latest)
Expand All @@ -45,6 +57,8 @@ jobs:
cmake --version
gcc --version

# Tests are skipped on Windows: processor_test needs zh_tn_*.fst, which
# are generated via pynini, and pynini has no Windows build.
cmake -S runtime -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF
Expand Down
4 changes: 4 additions & 0 deletions runtime/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ endif()

add_executable(processor_test processor_test.cc)
target_link_libraries(processor_test PUBLIC wetext_processor)
# Inject an absolute path to the *.fst models and golden data so the test does
# not depend on the working directory.
target_compile_definitions(processor_test PRIVATE
WETEXT_TN_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../../tn")
gtest_discover_tests(processor_test)
12 changes: 9 additions & 3 deletions runtime/test/processor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
#include "processor/wetext_processor.h"
#include "utils/wetext_string.h"

// Absolute path to the dir with *.fst models and golden data, injected by CMake
// so the test does not depend on the current working directory.
#ifndef WETEXT_TN_DIR
#define WETEXT_TN_DIR "../tn"
#endif

std::vector<std::pair<std::string, std::string>> ParseTestCase(
const std::string& file_path) {
const std::string delimiter = "=>";
Expand Down Expand Up @@ -52,8 +58,8 @@ class ProcessorTest
std::string spoken;

virtual void SetUp() {
std::string tagger_path = "../tn/zh_tn_tagger.fst";
std::string verbalizer_path = "../tn/zh_tn_verbalizer.fst";
std::string tagger_path = WETEXT_TN_DIR "/zh_tn_tagger.fst";
std::string verbalizer_path = WETEXT_TN_DIR "/zh_tn_verbalizer.fst";
processor = new wetext::Processor(tagger_path, verbalizer_path);
written = GetParam().first;
spoken = GetParam().second;
Expand All @@ -67,6 +73,6 @@ TEST_P(ProcessorTest, NormalizeTest) {
}

std::vector<std::pair<std::string, std::string>> test_cases =
ParseTestCase("../tn/chinese/test/data/normalizer.txt");
ParseTestCase(WETEXT_TN_DIR "/chinese/test/data/normalizer.txt");
INSTANTIATE_TEST_SUITE_P(NormalizeTest, ProcessorTest,
testing::ValuesIn(test_cases));
Loading