summaryrefslogtreecommitdiff
path: root/dealconvert/formats
diff options
context:
space:
mode:
Diffstat (limited to 'dealconvert/formats')
-rw-r--r--dealconvert/formats/__init__.py2
-rw-r--r--dealconvert/formats/ber.py2
-rw-r--r--dealconvert/formats/bhg.py4
-rw-r--r--dealconvert/formats/bri.py2
-rw-r--r--dealconvert/formats/dlm.py4
-rw-r--r--dealconvert/formats/rzd.py4
6 files changed, 11 insertions, 7 deletions
diff --git a/dealconvert/formats/__init__.py b/dealconvert/formats/__init__.py
index eea9fc6..9c37cf9 100644
--- a/dealconvert/formats/__init__.py
+++ b/dealconvert/formats/__init__.py
@@ -8,6 +8,8 @@ class DealFormat(object):
return self.parse_content(content)
def output(self, output_file, deal):
+ if not len(deal):
+ raise RuntimeError('Dealset is empty')
with open(output_file, 'wb') as out_file:
return self.output_content(out_file, deal)
diff --git a/dealconvert/formats/ber.py b/dealconvert/formats/ber.py
index 54ffd37..1ddd6c8 100644
--- a/dealconvert/formats/ber.py
+++ b/dealconvert/formats/ber.py
@@ -50,7 +50,7 @@ class BERFormat(DealFormat):
deal_str[j*13 + self.cards.index(card)] = str(i + 1)
except ValueError:
raise RuntimeError(
- 'invalid card character: %s' % (card))
+ 'invalid card character: %s in board %d' % (card, board.number))
if ' ' in deal_str:
warnings.warn('not all cards present in board %d' % (
board.number))
diff --git a/dealconvert/formats/bhg.py b/dealconvert/formats/bhg.py
index 23a1673..6964ea3 100644
--- a/dealconvert/formats/bhg.py
+++ b/dealconvert/formats/bhg.py
@@ -40,7 +40,7 @@ class BHGFormat(DealFormat):
return deals
def output_content(self, out_file, dealset):
- lines = [''] * (max([board.number for board in dealset])+2)
+ lines = [''] * (max([board.number for board in dealset])+2) if len(dealset) else []
for deal in dealset:
line = ''
for hand in range(0, 4):
@@ -51,7 +51,7 @@ class BHGFormat(DealFormat):
line += chr((65 if card < 26 else 71)+card)
except ValueError:
raise RuntimeError(
- 'invalid suit %s in board #%d' % (
+ 'invalid suit %s in board %d' % (
''.join(suit), deal.number))
lines[deal.number] = line
out_file.write('\r\n'.join(lines))
diff --git a/dealconvert/formats/bri.py b/dealconvert/formats/bri.py
index 942c4e4..1a4cc0f 100644
--- a/dealconvert/formats/bri.py
+++ b/dealconvert/formats/bri.py
@@ -67,5 +67,5 @@ class BRIFormat(DealFormat):
deal_str += '%02d' % (self.cards.index(card) + 13*i + 1)
except ValueError:
raise RuntimeError(
- 'invalid card character: %s' % (card))
+ 'invalid card character: %s in board %d' % (card, deal.number))
return deal_str
diff --git a/dealconvert/formats/dlm.py b/dealconvert/formats/dlm.py
index db9ac79..56f6e5d 100644
--- a/dealconvert/formats/dlm.py
+++ b/dealconvert/formats/dlm.py
@@ -66,7 +66,7 @@ class DLMFormat(DealFormat):
def output_content(self, out_file, dealset):
dealset = dealset[0:99]
board_numbers = [deal.number for deal in dealset]
- first_board = min(board_numbers)
+ first_board = min(board_numbers) if len(board_numbers) else 1
board_count = len(dealset)
for board in range(first_board, first_board+board_count):
if board not in board_numbers:
@@ -98,7 +98,7 @@ class DLMFormat(DealFormat):
try:
values[suit*13+self.cards.index(card)] = i
except ValueError:
- raise RuntimeError('invalid card: %s' % (card))
+ raise RuntimeError('invalid card: %s in board %d' % (card, board))
line = 'Board %02d=' % (board)
checksum = board
for i in range(0, 26):
diff --git a/dealconvert/formats/rzd.py b/dealconvert/formats/rzd.py
index 8ca1e97..93dbc45 100644
--- a/dealconvert/formats/rzd.py
+++ b/dealconvert/formats/rzd.py
@@ -51,11 +51,13 @@ class RZDFormat(DealFormat):
try:
idx = self.cards.index(card)
except ValueError:
- raise RuntimeError('invalid card: %s' % (card))
+ raise RuntimeError('invalid card: %s in board %d' % (card, deal.number))
values[idx*4+suit] = (i + offset)%4
for i in range(0, 13):
byte = 0
for j in range(0, 4):
+ if values[4*i+j] is None:
+ raise RuntimeError('missing card: %s%s in board %d' % ('SHDC'[j], self.cards[i], deal.number))
byte *= 4
byte += values[4*i+j]
value += chr(byte)