Skip to content

Commit

Permalink
Fix and re-enable TestScriptableSP for Windows (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthrok authored Jun 5, 2020
1 parent 5047245 commit 7df4853
Showing 1 changed file with 5 additions and 8 deletions.
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 @@ -196,11 +195,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 @@ -212,7 +211,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 @@ -221,7 +219,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

0 comments on commit 7df4853

Please sign in to comment.