Skip to content

Fix TestScriptableSP for Windows and include the relevant Windows tests online #799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2020
Merged
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
13 changes: 5 additions & 8 deletions test/data/test_functional.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import unittest
import sys
import uuid
import shutil
import unittest
import tempfile

import sentencepiece as spm
Expand Down Expand Up @@ -109,11 +108,11 @@ def encode_as_pieces(self, input: str):
class TestScriptableSP(unittest.TestCase):
def setUp(self):
model_path = get_asset_path('spm_example.model')
with tempfile.NamedTemporaryFile() as file:
torch.jit.script(ScriptableSP(model_path)).save(file.name)
self.model = torch.jit.load(file.name)
with tempfile.TemporaryDirectory() as dir_name:
jit_model_path = os.path.join(dir_name, 'spm_example.model')
torch.jit.script(ScriptableSP(model_path)).save(jit_model_path)
self.model = torch.jit.load(jit_model_path)

@unittest.skipIf(sys.platform == "win32", "FIXME: tempfile could not be opened twice on Windows")
def test_encode(self):
input = 'SentencePiece is an unsupervised text tokenizer and detokenizer'
expected = [
Expand All @@ -125,7 +124,6 @@ def test_encode(self):
output = self.model.encode(input)
self.assertEqual(expected, output)

@unittest.skipIf(sys.platform == "win32", "FIXME: tempfile could not be opened twice on Windows")
def test_encode_as_ids(self):
input = 'SentencePiece is an unsupervised text tokenizer and detokenizer'
expected = [
Expand All @@ -134,7 +132,6 @@ def test_encode_as_ids(self):
output = self.model.encode_as_ids(input)
self.assertEqual(expected, output)

@unittest.skipIf(sys.platform == "win32", "FIXME: tempfile could not be opened twice on Windows")
def test_encode_as_pieces(self):
input = 'SentencePiece is an unsupervised text tokenizer and detokenizer'
expected = [
Expand Down