Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: encoder checks if a line has all attributes
- Loading branch information
Showing
2 changed files
with
26 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
import unittest | ||
import arff | ||
|
||
|
||
class TestEncodeData(unittest.TestCase): | ||
def get_encoder(self): | ||
decoder = arff.ArffEncoder() | ||
return decoder | ||
def setUp(self): | ||
self.attributes = [('a1', 'INTEGER'), ('a2', 'INTEGER'), | ||
('a3', 'STRING'), ('a4', 'STRING')] | ||
self.encoder = arff.ArffEncoder() | ||
|
||
|
||
def test_simple(self): | ||
encoder = self.get_encoder() | ||
encoder = self.encoder | ||
|
||
fixture = [1, 3, 'Renato', 'Name with spaces'] | ||
result = encoder._encode_data(fixture) | ||
result = encoder._encode_data(fixture, self.attributes) | ||
expected = u"1,3,Renato,'Name with spaces'" | ||
|
||
self.assertEqual(result, expected) | ||
|
||
def test_null_value(self): | ||
encoder = self.get_encoder() | ||
encoder = self.encoder | ||
|
||
fixture = [1, None, 'Renato', ''] | ||
result = encoder._encode_data(fixture) | ||
result = encoder._encode_data(fixture, self.attributes) | ||
expected = u"1,?,Renato,?" | ||
|
||
self.assertEqual(result, expected) | ||
|
||
def test_too_short(self): | ||
encoder = self.encoder | ||
|
||
fixture = [1, None] | ||
self.assertRaises(arff.BadObject, encoder._encode_data, fixture, | ||
self.attributes) |