Skip to content

Commit

Permalink
Simplified the VISAN grammar.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernardo-MG committed Jul 23, 2015
1 parent a6e5ec2 commit a8340a8
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 45 deletions.
2 changes: 0 additions & 2 deletions config_cwr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@


1 change: 1 addition & 0 deletions config_cwr/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os

import yaml

from cwr.grammar.factory.config import rule_config_file

"""
Expand Down
28 changes: 1 addition & 27 deletions cwr/grammar/field/special.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,39 +327,13 @@ def visan(name=None):
if name is None:
name = 'V-ISAN Field'

version = basic.numeric(8)
version = version.setName('Version').setResultsName('version')

isan = basic.numeric(12)
isan = isan.setName('ISAN').setResultsName('isan')

episode = basic.numeric(4)
episode = episode.setName('Episode').setResultsName('episode')

check_digit = basic.numeric(1)
check_digit = check_digit.setName('Check Digit') \
.setResultsName('check_digit')

field = pp.Group(version + isan + episode + check_digit)

field.setParseAction(lambda v: _to_visan(v[0]))
field = pp.Regex('[0-9]{25}')

field.setName(name)

return field.setResultsName('visan')


def _to_visan(parsed):
"""
Transforms the data from a V-ISAN field into a VISAN instance.
:param parsed: the data parsed from a V-ISAN field
:return: a VISAN instance created from the data
"""
return VISAN(parsed.version, parsed.isan, parsed.episode,
parsed.check_digit)


def audio_visual_key(name=None):
"""
Creates the grammar for an Audio Visual Key code.
Expand Down
10 changes: 2 additions & 8 deletions tests/grammar/factory/record/test_work_origin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ def test_full(self):
self.assertEqual(1234, result.cut_number)
self.assertEqual('THE LIBRARY', result.library)
self.assertEqual('B', result.bltvr)
self.assertEqual(12345678, result.visan.version)
self.assertEqual(123456789012, result.visan.isan)
self.assertEqual(1234, result.visan.episode)
self.assertEqual(1, result.visan.check_digit)
self.assertEqual('1234567812345678901212341', result.visan)
self.assertEqual('ABDFE', result.production_n)
self.assertEqual('EPISODE TITLE', result.episode_title)
self.assertEqual('ABD12345', result.episode_n)
Expand All @@ -59,10 +56,7 @@ def test_common(self):
self.assertEqual(0, result.cut_number)
self.assertEqual(None, result.library)
self.assertEqual(None, result.bltvr)
self.assertEqual(0, result.visan.version)
self.assertEqual(0, result.visan.isan)
self.assertEqual(0, result.visan.episode)
self.assertEqual(0, result.visan.check_digit)
self.assertEqual('0000000000000000000000000', result.visan)
self.assertEqual(None, result.production_n)
self.assertEqual('EPISODE TITLE', result.episode_title)
self.assertEqual(None, result.episode_n)
Expand Down
10 changes: 2 additions & 8 deletions tests/grammar/field/special/test_visan.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ def test_common(self):

result = self.ean.parseString(code)[0]

self.assertEqual(1234567, result.version)
self.assertEqual(12345678912, result.isan)
self.assertEqual(123, result.episode)
self.assertEqual(1, result.check_digit)
self.assertEqual('0123456701234567891201231', result)


class TestVISANResultName(unittest.TestCase):
Expand All @@ -43,7 +40,4 @@ def test_common(self):

result = self.ean.parseString(code)

self.assertEqual(1234567, result.visan.version)
self.assertEqual(12345678912, result.visan.isan)
self.assertEqual(123, result.visan.episode)
self.assertEqual(1, result.visan.check_digit)
self.assertEqual('0123456701234567891201231', result.visan)

0 comments on commit a8340a8

Please sign in to comment.