prompt
large_stringlengths 72
9.34k
| completion
large_stringlengths 0
7.61k
|
---|---|
<|file_name|>setAwayMessageEvent.py<|end_file_name|><|fim▁begin|>from common.log import logUtils as log
from constants import clientPackets
from constants import serverPackets
def handle(userToken, packetData):
# get token data
username = userToken.username
# Read packet data
packetData = clientPackets.setAwayMessage(packetData)
# Set token away message
userToken.awayMessage = packetData["awayMessage"]
# Send private message from fokabot
if packetData["awayMessage"] == "":
<|fim_middle|>
else:
fokaMessage = "Your away message is now: {}".format(packetData["awayMessage"])
userToken.enqueue(serverPackets.sendMessage("FokaBot", username, fokaMessage))
log.info("{} has changed their away message to: {}".format(username, packetData["awayMessage"]))
<|fim▁end|> | fokaMessage = "Your away message has been reset" |
<|file_name|>setAwayMessageEvent.py<|end_file_name|><|fim▁begin|>from common.log import logUtils as log
from constants import clientPackets
from constants import serverPackets
def handle(userToken, packetData):
# get token data
username = userToken.username
# Read packet data
packetData = clientPackets.setAwayMessage(packetData)
# Set token away message
userToken.awayMessage = packetData["awayMessage"]
# Send private message from fokabot
if packetData["awayMessage"] == "":
fokaMessage = "Your away message has been reset"
else:
<|fim_middle|>
userToken.enqueue(serverPackets.sendMessage("FokaBot", username, fokaMessage))
log.info("{} has changed their away message to: {}".format(username, packetData["awayMessage"]))
<|fim▁end|> | fokaMessage = "Your away message is now: {}".format(packetData["awayMessage"]) |
<|file_name|>setAwayMessageEvent.py<|end_file_name|><|fim▁begin|>from common.log import logUtils as log
from constants import clientPackets
from constants import serverPackets
def <|fim_middle|>(userToken, packetData):
# get token data
username = userToken.username
# Read packet data
packetData = clientPackets.setAwayMessage(packetData)
# Set token away message
userToken.awayMessage = packetData["awayMessage"]
# Send private message from fokabot
if packetData["awayMessage"] == "":
fokaMessage = "Your away message has been reset"
else:
fokaMessage = "Your away message is now: {}".format(packetData["awayMessage"])
userToken.enqueue(serverPackets.sendMessage("FokaBot", username, fokaMessage))
log.info("{} has changed their away message to: {}".format(username, packetData["awayMessage"]))
<|fim▁end|> | handle |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()<|fim▁hole|>
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26<|fim▁end|> | |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
<|fim_middle|>
<|fim▁end|> | def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26 |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
<|fim_middle|>
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | return interpret(func, args) |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
<|fim_middle|>
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24 |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
<|fim_middle|>
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | return p[0] |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
<|fim_middle|>
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | return BoxInt(p[0].getint() + p[2].getint()) |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
<|fim_middle|>
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | return BoxInt(int(p[0].getstr())) |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
<|fim_middle|>
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint() |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
<|fim_middle|>
<|fim▁end|> | pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26 |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
<|fim_middle|>
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | state.count += 1
return p[0] |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
<|fim_middle|>
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | state.count += 1
return BoxInt(p[0].getint() + p[2].getint()) |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
<|fim_middle|>
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | state.count += 1
return BoxInt(int(p[0].getstr())) |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
<|fim_middle|>
assert self.run(f, []) == 26
<|fim▁end|> | state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def <|fim_middle|>(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | run |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def <|fim_middle|>(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | test_basic |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def <|fim_middle|>(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | main |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def <|fim_middle|>(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | expr_op |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def <|fim_middle|>(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | expr_num |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def <|fim_middle|>(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | f |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def <|fim_middle|>(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | test_state |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def <|fim_middle|>(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | main |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def <|fim_middle|>(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | expression_plus |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def <|fim_middle|>(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def f():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | expression_number |
<|file_name|>test_ztranslation.py<|end_file_name|><|fim▁begin|>import py
try:
from pypy.rpython.test.test_llinterp import interpret
except ImportError:
py.test.skip('Needs PyPy to be on the PYTHONPATH')
from rply import ParserGenerator, Token
from rply.errors import ParserGeneratorWarning
from .base import BaseTests
from .utils import FakeLexer, BoxInt, ParserState
class TestTranslation(BaseTests):
def run(self, func, args):
return interpret(func, args)
def test_basic(self):
pg = ParserGenerator(["NUMBER", "PLUS"])
@pg.production("main : expr")
def main(p):
return p[0]
@pg.production("expr : expr PLUS expr")
def expr_op(p):
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expr : NUMBER")
def expr_num(p):
return BoxInt(int(p[0].getstr()))
with self.assert_warns(ParserGeneratorWarning, "1 shift/reduce conflict"):
parser = pg.build()
def f(n):
return parser.parse(FakeLexer([
Token("NUMBER", str(n)),
Token("PLUS", "+"),
Token("NUMBER", str(n))
])).getint()
assert self.run(f, [12]) == 24
def test_state(self):
pg = ParserGenerator(["NUMBER", "PLUS"], precedence=[
("left", ["PLUS"]),
])
@pg.production("main : expression")
def main(state, p):
state.count += 1
return p[0]
@pg.production("expression : expression PLUS expression")
def expression_plus(state, p):
state.count += 1
return BoxInt(p[0].getint() + p[2].getint())
@pg.production("expression : NUMBER")
def expression_number(state, p):
state.count += 1
return BoxInt(int(p[0].getstr()))
parser = pg.build()
def <|fim_middle|>():
state = ParserState()
return parser.parse(FakeLexer([
Token("NUMBER", "10"),
Token("PLUS", "+"),
Token("NUMBER", "12"),
Token("PLUS", "+"),
Token("NUMBER", "-2"),
]), state=state).getint() + state.count
assert self.run(f, []) == 26
<|fim▁end|> | f |
<|file_name|>skpicture_printer_unittest.py<|end_file_name|><|fim▁begin|># Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import shutil
import tempfile
from telemetry import decorators
from telemetry.testing import options_for_unittests
from telemetry.testing import page_test_test_case
from measurements import skpicture_printer
class SkpicturePrinterUnitTest(page_test_test_case.PageTestTestCase):
def setUp(self):
self._options = options_for_unittests.GetCopy()
self._skp_outdir = tempfile.mkdtemp('_skp_test')
def tearDown(self):
shutil.rmtree(self._skp_outdir)
@decorators.Disabled('android')
def testSkpicturePrinter(self):
ps = self.CreateStorySetFromFileInUnittestDataDir('blank.html')
measurement = skpicture_printer.SkpicturePrinter(self._skp_outdir)
results = self.RunMeasurement(measurement, ps, options=self._options)
# Picture printing is not supported on all platforms.
if results.failures:
assert 'not supported' in results.failures[0].exc_info[1].message
return
saved_picture_count = results.FindAllPageSpecificValuesNamed(
'saved_picture_count')<|fim▁hole|> self.assertEquals(len(saved_picture_count), 1)
self.assertGreater(saved_picture_count[0].GetRepresentativeNumber(), 0)<|fim▁end|> | |
<|file_name|>skpicture_printer_unittest.py<|end_file_name|><|fim▁begin|># Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import shutil
import tempfile
from telemetry import decorators
from telemetry.testing import options_for_unittests
from telemetry.testing import page_test_test_case
from measurements import skpicture_printer
class SkpicturePrinterUnitTest(page_test_test_case.PageTestTestCase):
<|fim_middle|>
<|fim▁end|> | def setUp(self):
self._options = options_for_unittests.GetCopy()
self._skp_outdir = tempfile.mkdtemp('_skp_test')
def tearDown(self):
shutil.rmtree(self._skp_outdir)
@decorators.Disabled('android')
def testSkpicturePrinter(self):
ps = self.CreateStorySetFromFileInUnittestDataDir('blank.html')
measurement = skpicture_printer.SkpicturePrinter(self._skp_outdir)
results = self.RunMeasurement(measurement, ps, options=self._options)
# Picture printing is not supported on all platforms.
if results.failures:
assert 'not supported' in results.failures[0].exc_info[1].message
return
saved_picture_count = results.FindAllPageSpecificValuesNamed(
'saved_picture_count')
self.assertEquals(len(saved_picture_count), 1)
self.assertGreater(saved_picture_count[0].GetRepresentativeNumber(), 0) |
<|file_name|>skpicture_printer_unittest.py<|end_file_name|><|fim▁begin|># Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import shutil
import tempfile
from telemetry import decorators
from telemetry.testing import options_for_unittests
from telemetry.testing import page_test_test_case
from measurements import skpicture_printer
class SkpicturePrinterUnitTest(page_test_test_case.PageTestTestCase):
def setUp(self):
<|fim_middle|>
def tearDown(self):
shutil.rmtree(self._skp_outdir)
@decorators.Disabled('android')
def testSkpicturePrinter(self):
ps = self.CreateStorySetFromFileInUnittestDataDir('blank.html')
measurement = skpicture_printer.SkpicturePrinter(self._skp_outdir)
results = self.RunMeasurement(measurement, ps, options=self._options)
# Picture printing is not supported on all platforms.
if results.failures:
assert 'not supported' in results.failures[0].exc_info[1].message
return
saved_picture_count = results.FindAllPageSpecificValuesNamed(
'saved_picture_count')
self.assertEquals(len(saved_picture_count), 1)
self.assertGreater(saved_picture_count[0].GetRepresentativeNumber(), 0)
<|fim▁end|> | self._options = options_for_unittests.GetCopy()
self._skp_outdir = tempfile.mkdtemp('_skp_test') |
<|file_name|>skpicture_printer_unittest.py<|end_file_name|><|fim▁begin|># Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import shutil
import tempfile
from telemetry import decorators
from telemetry.testing import options_for_unittests
from telemetry.testing import page_test_test_case
from measurements import skpicture_printer
class SkpicturePrinterUnitTest(page_test_test_case.PageTestTestCase):
def setUp(self):
self._options = options_for_unittests.GetCopy()
self._skp_outdir = tempfile.mkdtemp('_skp_test')
def tearDown(self):
<|fim_middle|>
@decorators.Disabled('android')
def testSkpicturePrinter(self):
ps = self.CreateStorySetFromFileInUnittestDataDir('blank.html')
measurement = skpicture_printer.SkpicturePrinter(self._skp_outdir)
results = self.RunMeasurement(measurement, ps, options=self._options)
# Picture printing is not supported on all platforms.
if results.failures:
assert 'not supported' in results.failures[0].exc_info[1].message
return
saved_picture_count = results.FindAllPageSpecificValuesNamed(
'saved_picture_count')
self.assertEquals(len(saved_picture_count), 1)
self.assertGreater(saved_picture_count[0].GetRepresentativeNumber(), 0)
<|fim▁end|> | shutil.rmtree(self._skp_outdir) |
<|file_name|>skpicture_printer_unittest.py<|end_file_name|><|fim▁begin|># Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import shutil
import tempfile
from telemetry import decorators
from telemetry.testing import options_for_unittests
from telemetry.testing import page_test_test_case
from measurements import skpicture_printer
class SkpicturePrinterUnitTest(page_test_test_case.PageTestTestCase):
def setUp(self):
self._options = options_for_unittests.GetCopy()
self._skp_outdir = tempfile.mkdtemp('_skp_test')
def tearDown(self):
shutil.rmtree(self._skp_outdir)
@decorators.Disabled('android')
def testSkpicturePrinter(self):
<|fim_middle|>
<|fim▁end|> | ps = self.CreateStorySetFromFileInUnittestDataDir('blank.html')
measurement = skpicture_printer.SkpicturePrinter(self._skp_outdir)
results = self.RunMeasurement(measurement, ps, options=self._options)
# Picture printing is not supported on all platforms.
if results.failures:
assert 'not supported' in results.failures[0].exc_info[1].message
return
saved_picture_count = results.FindAllPageSpecificValuesNamed(
'saved_picture_count')
self.assertEquals(len(saved_picture_count), 1)
self.assertGreater(saved_picture_count[0].GetRepresentativeNumber(), 0) |
<|file_name|>skpicture_printer_unittest.py<|end_file_name|><|fim▁begin|># Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import shutil
import tempfile
from telemetry import decorators
from telemetry.testing import options_for_unittests
from telemetry.testing import page_test_test_case
from measurements import skpicture_printer
class SkpicturePrinterUnitTest(page_test_test_case.PageTestTestCase):
def setUp(self):
self._options = options_for_unittests.GetCopy()
self._skp_outdir = tempfile.mkdtemp('_skp_test')
def tearDown(self):
shutil.rmtree(self._skp_outdir)
@decorators.Disabled('android')
def testSkpicturePrinter(self):
ps = self.CreateStorySetFromFileInUnittestDataDir('blank.html')
measurement = skpicture_printer.SkpicturePrinter(self._skp_outdir)
results = self.RunMeasurement(measurement, ps, options=self._options)
# Picture printing is not supported on all platforms.
if results.failures:
<|fim_middle|>
saved_picture_count = results.FindAllPageSpecificValuesNamed(
'saved_picture_count')
self.assertEquals(len(saved_picture_count), 1)
self.assertGreater(saved_picture_count[0].GetRepresentativeNumber(), 0)
<|fim▁end|> | assert 'not supported' in results.failures[0].exc_info[1].message
return |
<|file_name|>skpicture_printer_unittest.py<|end_file_name|><|fim▁begin|># Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import shutil
import tempfile
from telemetry import decorators
from telemetry.testing import options_for_unittests
from telemetry.testing import page_test_test_case
from measurements import skpicture_printer
class SkpicturePrinterUnitTest(page_test_test_case.PageTestTestCase):
def <|fim_middle|>(self):
self._options = options_for_unittests.GetCopy()
self._skp_outdir = tempfile.mkdtemp('_skp_test')
def tearDown(self):
shutil.rmtree(self._skp_outdir)
@decorators.Disabled('android')
def testSkpicturePrinter(self):
ps = self.CreateStorySetFromFileInUnittestDataDir('blank.html')
measurement = skpicture_printer.SkpicturePrinter(self._skp_outdir)
results = self.RunMeasurement(measurement, ps, options=self._options)
# Picture printing is not supported on all platforms.
if results.failures:
assert 'not supported' in results.failures[0].exc_info[1].message
return
saved_picture_count = results.FindAllPageSpecificValuesNamed(
'saved_picture_count')
self.assertEquals(len(saved_picture_count), 1)
self.assertGreater(saved_picture_count[0].GetRepresentativeNumber(), 0)
<|fim▁end|> | setUp |
<|file_name|>skpicture_printer_unittest.py<|end_file_name|><|fim▁begin|># Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import shutil
import tempfile
from telemetry import decorators
from telemetry.testing import options_for_unittests
from telemetry.testing import page_test_test_case
from measurements import skpicture_printer
class SkpicturePrinterUnitTest(page_test_test_case.PageTestTestCase):
def setUp(self):
self._options = options_for_unittests.GetCopy()
self._skp_outdir = tempfile.mkdtemp('_skp_test')
def <|fim_middle|>(self):
shutil.rmtree(self._skp_outdir)
@decorators.Disabled('android')
def testSkpicturePrinter(self):
ps = self.CreateStorySetFromFileInUnittestDataDir('blank.html')
measurement = skpicture_printer.SkpicturePrinter(self._skp_outdir)
results = self.RunMeasurement(measurement, ps, options=self._options)
# Picture printing is not supported on all platforms.
if results.failures:
assert 'not supported' in results.failures[0].exc_info[1].message
return
saved_picture_count = results.FindAllPageSpecificValuesNamed(
'saved_picture_count')
self.assertEquals(len(saved_picture_count), 1)
self.assertGreater(saved_picture_count[0].GetRepresentativeNumber(), 0)
<|fim▁end|> | tearDown |
<|file_name|>skpicture_printer_unittest.py<|end_file_name|><|fim▁begin|># Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import shutil
import tempfile
from telemetry import decorators
from telemetry.testing import options_for_unittests
from telemetry.testing import page_test_test_case
from measurements import skpicture_printer
class SkpicturePrinterUnitTest(page_test_test_case.PageTestTestCase):
def setUp(self):
self._options = options_for_unittests.GetCopy()
self._skp_outdir = tempfile.mkdtemp('_skp_test')
def tearDown(self):
shutil.rmtree(self._skp_outdir)
@decorators.Disabled('android')
def <|fim_middle|>(self):
ps = self.CreateStorySetFromFileInUnittestDataDir('blank.html')
measurement = skpicture_printer.SkpicturePrinter(self._skp_outdir)
results = self.RunMeasurement(measurement, ps, options=self._options)
# Picture printing is not supported on all platforms.
if results.failures:
assert 'not supported' in results.failures[0].exc_info[1].message
return
saved_picture_count = results.FindAllPageSpecificValuesNamed(
'saved_picture_count')
self.assertEquals(len(saved_picture_count), 1)
self.assertGreater(saved_picture_count[0].GetRepresentativeNumber(), 0)
<|fim▁end|> | testSkpicturePrinter |
<|file_name|>urls.py<|end_file_name|><|fim▁begin|># Copyright (c) 2010 by Yaco Sistemas <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this programe. If not, see <http://www.gnu.org/licenses/>.
from django.conf.urls.defaults import patterns, url
urlpatterns = patterns('autoreports.views',<|fim▁hole|> url(r'^(category/(?P<category_key>[\w-]+)/)?$', 'reports_list', name='reports_list'),
url(r'^(?P<registry_key>[\w-]+)/$', 'reports_api', name='reports_api'),
url(r'^(?P<registry_key>[\w-]+)/(?P<report_id>\d+)/$', 'reports_api', name='reports_api'),
url(r'^(?P<registry_key>[\w-]+)/reports/$', 'reports_api_list', name='reports_api_list'),
url(r'^(?P<registry_key>[\w-]+)/wizard/$', 'reports_api_wizard', name='reports_api_wizard'),
url(r'^(?P<registry_key>[\w-]+)/wizard/(?P<report_id>\d+)/$', 'reports_api_wizard', name='reports_api_wizard'),
url(r'^(?P<app_name>[\w-]+)/(?P<model_name>[\w-]+)/$', 'reports_view', name='reports_view'),
)<|fim▁end|> | url(r'^ajax/fields/tree/$', 'reports_ajax_fields', name='reports_ajax_fields'),
url(r'^ajax/fields/options/$', 'reports_ajax_fields_options', name='reports_ajax_fields_options'),
|
<|file_name|>PROC_A_SUBJECT_D002015.py<|end_file_name|><|fim▁begin|>#coding=UTF-8
from pyspark import SparkContext, SparkConf, SQLContext, Row, HiveContext
from pyspark.sql.types import *
from datetime import date, datetime, timedelta
import sys, re, os
st = datetime.now()
conf = SparkConf().setAppName('PROC_A_SUBJECT_D002015').setMaster(sys.argv[2])
sc = SparkContext(conf = conf)
sc.setLogLevel('WARN')
if len(sys.argv) > 5:
if sys.argv[5] == "hive":<|fim▁hole|> sqlContext = SQLContext(sc)
hdfs = sys.argv[3]
dbname = sys.argv[4]
#处理需要使用的日期
etl_date = sys.argv[1]
#etl日期
V_DT = etl_date
#上一日日期
V_DT_LD = (date(int(etl_date[0:4]), int(etl_date[4:6]), int(etl_date[6:8])) + timedelta(-1)).strftime("%Y%m%d")
#月初日期
V_DT_FMD = date(int(etl_date[0:4]), int(etl_date[4:6]), 1).strftime("%Y%m%d")
#上月末日期
V_DT_LMD = (date(int(etl_date[0:4]), int(etl_date[4:6]), 1) + timedelta(-1)).strftime("%Y%m%d")
#10位日期
V_DT10 = (date(int(etl_date[0:4]), int(etl_date[4:6]), int(etl_date[6:8]))).strftime("%Y-%m-%d")
V_STEP = 0
ACRM_F_CI_ASSET_BUSI_PROTO = sqlContext.read.parquet(hdfs+'/ACRM_F_CI_ASSET_BUSI_PROTO/*')
ACRM_F_CI_ASSET_BUSI_PROTO.registerTempTable("ACRM_F_CI_ASSET_BUSI_PROTO")
#任务[21] 001-01::
V_STEP = V_STEP + 1
sql = """
SELECT CAST(A.CUST_ID AS VARCHAR(32)) AS CUST_ID
,CAST('' AS VARCHAR(20)) AS ORG_ID --插入的空值,包顺龙2017/05/13
,CAST('D002015' AS VARCHAR(20)) AS INDEX_CODE
,CAST(SUM(TAKE_CGT_LINE) AS DECIMAL(22,2)) AS INDEX_VALUE
,CAST(SUBSTR(V_DT, 1, 7) AS VARCHAR(7)) AS YEAR_MONTH
,CAST(V_DT AS DATE) AS ETL_DATE
,CAST(A.CUST_TYP AS VARCHAR(5)) AS CUST_TYPE
,CAST(A.FR_ID AS VARCHAR(5)) AS FR_ID
FROM ACRM_F_CI_ASSET_BUSI_PROTO A
WHERE A.BAL > 0
AND A.LN_APCL_FLG = 'N'
AND(A.PRODUCT_ID LIKE '1010%'
OR A.PRODUCT_ID LIKE '1030%'
OR A.PRODUCT_ID LIKE '1040%'
OR A.PRODUCT_ID LIKE '1050%'
OR A.PRODUCT_ID LIKE '1060%'
OR A.PRODUCT_ID LIKE '1070%'
OR A.PRODUCT_ID LIKE '2010%'
OR A.PRODUCT_ID LIKE '2020%'
OR A.PRODUCT_ID LIKE '2030%'
OR A.PRODUCT_ID LIKE '2040%'
OR A.PRODUCT_ID LIKE '2050%')
GROUP BY A.CUST_ID
,A.CUST_TYP
,A.FR_ID """
sql = re.sub(r"\bV_DT\b", "'"+V_DT10+"'", sql)
ACRM_A_TARGET_D002015 = sqlContext.sql(sql)
ACRM_A_TARGET_D002015.registerTempTable("ACRM_A_TARGET_D002015")
dfn="ACRM_A_TARGET_D002015/"+V_DT+".parquet"
ACRM_A_TARGET_D002015.cache()
nrows = ACRM_A_TARGET_D002015.count()
ACRM_A_TARGET_D002015.write.save(path=hdfs + '/' + dfn, mode='overwrite')
ACRM_A_TARGET_D002015.unpersist()
ACRM_F_CI_ASSET_BUSI_PROTO.unpersist()
ret = os.system("hdfs dfs -rm -r /"+dbname+"/ACRM_A_TARGET_D002015/"+V_DT_LD+".parquet")
et = datetime.now()
print("Step %d start[%s] end[%s] use %d seconds, insert ACRM_A_TARGET_D002015 lines %d") % (V_STEP, st.strftime("%H:%M:%S"), et.strftime("%H:%M:%S"), (et-st).seconds, nrows)<|fim▁end|> | sqlContext = HiveContext(sc)
else: |
<|file_name|>PROC_A_SUBJECT_D002015.py<|end_file_name|><|fim▁begin|>#coding=UTF-8
from pyspark import SparkContext, SparkConf, SQLContext, Row, HiveContext
from pyspark.sql.types import *
from datetime import date, datetime, timedelta
import sys, re, os
st = datetime.now()
conf = SparkConf().setAppName('PROC_A_SUBJECT_D002015').setMaster(sys.argv[2])
sc = SparkContext(conf = conf)
sc.setLogLevel('WARN')
if len(sys.argv) > 5:
<|fim_middle|>
else:
sqlContext = SQLContext(sc)
hdfs = sys.argv[3]
dbname = sys.argv[4]
#处理需要使用的日期
etl_date = sys.argv[1]
#etl日期
V_DT = etl_date
#上一日日期
V_DT_LD = (date(int(etl_date[0:4]), int(etl_date[4:6]), int(etl_date[6:8])) + timedelta(-1)).strftime("%Y%m%d")
#月初日期
V_DT_FMD = date(int(etl_date[0:4]), int(etl_date[4:6]), 1).strftime("%Y%m%d")
#上月末日期
V_DT_LMD = (date(int(etl_date[0:4]), int(etl_date[4:6]), 1) + timedelta(-1)).strftime("%Y%m%d")
#10位日期
V_DT10 = (date(int(etl_date[0:4]), int(etl_date[4:6]), int(etl_date[6:8]))).strftime("%Y-%m-%d")
V_STEP = 0
ACRM_F_CI_ASSET_BUSI_PROTO = sqlContext.read.parquet(hdfs+'/ACRM_F_CI_ASSET_BUSI_PROTO/*')
ACRM_F_CI_ASSET_BUSI_PROTO.registerTempTable("ACRM_F_CI_ASSET_BUSI_PROTO")
#任务[21] 001-01::
V_STEP = V_STEP + 1
sql = """
SELECT CAST(A.CUST_ID AS VARCHAR(32)) AS CUST_ID
,CAST('' AS VARCHAR(20)) AS ORG_ID --插入的空值,包顺龙2017/05/13
,CAST('D002015' AS VARCHAR(20)) AS INDEX_CODE
,CAST(SUM(TAKE_CGT_LINE) AS DECIMAL(22,2)) AS INDEX_VALUE
,CAST(SUBSTR(V_DT, 1, 7) AS VARCHAR(7)) AS YEAR_MONTH
,CAST(V_DT AS DATE) AS ETL_DATE
,CAST(A.CUST_TYP AS VARCHAR(5)) AS CUST_TYPE
,CAST(A.FR_ID AS VARCHAR(5)) AS FR_ID
FROM ACRM_F_CI_ASSET_BUSI_PROTO A
WHERE A.BAL > 0
AND A.LN_APCL_FLG = 'N'
AND(A.PRODUCT_ID LIKE '1010%'
OR A.PRODUCT_ID LIKE '1030%'
OR A.PRODUCT_ID LIKE '1040%'
OR A.PRODUCT_ID LIKE '1050%'
OR A.PRODUCT_ID LIKE '1060%'
OR A.PRODUCT_ID LIKE '1070%'
OR A.PRODUCT_ID LIKE '2010%'
OR A.PRODUCT_ID LIKE '2020%'
OR A.PRODUCT_ID LIKE '2030%'
OR A.PRODUCT_ID LIKE '2040%'
OR A.PRODUCT_ID LIKE '2050%')
GROUP BY A.CUST_ID
,A.CUST_TYP
,A.FR_ID """
sql = re.sub(r"\bV_DT\b", "'"+V_DT10+"'", sql)
ACRM_A_TARGET_D002015 = sqlContext.sql(sql)
ACRM_A_TARGET_D002015.registerTempTable("ACRM_A_TARGET_D002015")
dfn="ACRM_A_TARGET_D002015/"+V_DT+".parquet"
ACRM_A_TARGET_D002015.cache()
nrows = ACRM_A_TARGET_D002015.count()
ACRM_A_TARGET_D002015.write.save(path=hdfs + '/' + dfn, mode='overwrite')
ACRM_A_TARGET_D002015.unpersist()
ACRM_F_CI_ASSET_BUSI_PROTO.unpersist()
ret = os.system("hdfs dfs -rm -r /"+dbname+"/ACRM_A_TARGET_D002015/"+V_DT_LD+".parquet")
et = datetime.now()
print("Step %d start[%s] end[%s] use %d seconds, insert ACRM_A_TARGET_D002015 lines %d") % (V_STEP, st.strftime("%H:%M:%S"), et.strftime("%H:%M:%S"), (et-st).seconds, nrows)
<|fim▁end|> | if sys.argv[5] == "hive":
sqlContext = HiveContext(sc) |
<|file_name|>PROC_A_SUBJECT_D002015.py<|end_file_name|><|fim▁begin|>#coding=UTF-8
from pyspark import SparkContext, SparkConf, SQLContext, Row, HiveContext
from pyspark.sql.types import *
from datetime import date, datetime, timedelta
import sys, re, os
st = datetime.now()
conf = SparkConf().setAppName('PROC_A_SUBJECT_D002015').setMaster(sys.argv[2])
sc = SparkContext(conf = conf)
sc.setLogLevel('WARN')
if len(sys.argv) > 5:
if sys.argv[5] == "hive":
<|fim_middle|>
else:
sqlContext = SQLContext(sc)
hdfs = sys.argv[3]
dbname = sys.argv[4]
#处理需要使用的日期
etl_date = sys.argv[1]
#etl日期
V_DT = etl_date
#上一日日期
V_DT_LD = (date(int(etl_date[0:4]), int(etl_date[4:6]), int(etl_date[6:8])) + timedelta(-1)).strftime("%Y%m%d")
#月初日期
V_DT_FMD = date(int(etl_date[0:4]), int(etl_date[4:6]), 1).strftime("%Y%m%d")
#上月末日期
V_DT_LMD = (date(int(etl_date[0:4]), int(etl_date[4:6]), 1) + timedelta(-1)).strftime("%Y%m%d")
#10位日期
V_DT10 = (date(int(etl_date[0:4]), int(etl_date[4:6]), int(etl_date[6:8]))).strftime("%Y-%m-%d")
V_STEP = 0
ACRM_F_CI_ASSET_BUSI_PROTO = sqlContext.read.parquet(hdfs+'/ACRM_F_CI_ASSET_BUSI_PROTO/*')
ACRM_F_CI_ASSET_BUSI_PROTO.registerTempTable("ACRM_F_CI_ASSET_BUSI_PROTO")
#任务[21] 001-01::
V_STEP = V_STEP + 1
sql = """
SELECT CAST(A.CUST_ID AS VARCHAR(32)) AS CUST_ID
,CAST('' AS VARCHAR(20)) AS ORG_ID --插入的空值,包顺龙2017/05/13
,CAST('D002015' AS VARCHAR(20)) AS INDEX_CODE
,CAST(SUM(TAKE_CGT_LINE) AS DECIMAL(22,2)) AS INDEX_VALUE
,CAST(SUBSTR(V_DT, 1, 7) AS VARCHAR(7)) AS YEAR_MONTH
,CAST(V_DT AS DATE) AS ETL_DATE
,CAST(A.CUST_TYP AS VARCHAR(5)) AS CUST_TYPE
,CAST(A.FR_ID AS VARCHAR(5)) AS FR_ID
FROM ACRM_F_CI_ASSET_BUSI_PROTO A
WHERE A.BAL > 0
AND A.LN_APCL_FLG = 'N'
AND(A.PRODUCT_ID LIKE '1010%'
OR A.PRODUCT_ID LIKE '1030%'
OR A.PRODUCT_ID LIKE '1040%'
OR A.PRODUCT_ID LIKE '1050%'
OR A.PRODUCT_ID LIKE '1060%'
OR A.PRODUCT_ID LIKE '1070%'
OR A.PRODUCT_ID LIKE '2010%'
OR A.PRODUCT_ID LIKE '2020%'
OR A.PRODUCT_ID LIKE '2030%'
OR A.PRODUCT_ID LIKE '2040%'
OR A.PRODUCT_ID LIKE '2050%')
GROUP BY A.CUST_ID
,A.CUST_TYP
,A.FR_ID """
sql = re.sub(r"\bV_DT\b", "'"+V_DT10+"'", sql)
ACRM_A_TARGET_D002015 = sqlContext.sql(sql)
ACRM_A_TARGET_D002015.registerTempTable("ACRM_A_TARGET_D002015")
dfn="ACRM_A_TARGET_D002015/"+V_DT+".parquet"
ACRM_A_TARGET_D002015.cache()
nrows = ACRM_A_TARGET_D002015.count()
ACRM_A_TARGET_D002015.write.save(path=hdfs + '/' + dfn, mode='overwrite')
ACRM_A_TARGET_D002015.unpersist()
ACRM_F_CI_ASSET_BUSI_PROTO.unpersist()
ret = os.system("hdfs dfs -rm -r /"+dbname+"/ACRM_A_TARGET_D002015/"+V_DT_LD+".parquet")
et = datetime.now()
print("Step %d start[%s] end[%s] use %d seconds, insert ACRM_A_TARGET_D002015 lines %d") % (V_STEP, st.strftime("%H:%M:%S"), et.strftime("%H:%M:%S"), (et-st).seconds, nrows)
<|fim▁end|> | sqlContext = HiveContext(sc) |
<|file_name|>PROC_A_SUBJECT_D002015.py<|end_file_name|><|fim▁begin|>#coding=UTF-8
from pyspark import SparkContext, SparkConf, SQLContext, Row, HiveContext
from pyspark.sql.types import *
from datetime import date, datetime, timedelta
import sys, re, os
st = datetime.now()
conf = SparkConf().setAppName('PROC_A_SUBJECT_D002015').setMaster(sys.argv[2])
sc = SparkContext(conf = conf)
sc.setLogLevel('WARN')
if len(sys.argv) > 5:
if sys.argv[5] == "hive":
sqlContext = HiveContext(sc)
else:
<|fim_middle|>
hdfs = sys.argv[3]
dbname = sys.argv[4]
#处理需要使用的日期
etl_date = sys.argv[1]
#etl日期
V_DT = etl_date
#上一日日期
V_DT_LD = (date(int(etl_date[0:4]), int(etl_date[4:6]), int(etl_date[6:8])) + timedelta(-1)).strftime("%Y%m%d")
#月初日期
V_DT_FMD = date(int(etl_date[0:4]), int(etl_date[4:6]), 1).strftime("%Y%m%d")
#上月末日期
V_DT_LMD = (date(int(etl_date[0:4]), int(etl_date[4:6]), 1) + timedelta(-1)).strftime("%Y%m%d")
#10位日期
V_DT10 = (date(int(etl_date[0:4]), int(etl_date[4:6]), int(etl_date[6:8]))).strftime("%Y-%m-%d")
V_STEP = 0
ACRM_F_CI_ASSET_BUSI_PROTO = sqlContext.read.parquet(hdfs+'/ACRM_F_CI_ASSET_BUSI_PROTO/*')
ACRM_F_CI_ASSET_BUSI_PROTO.registerTempTable("ACRM_F_CI_ASSET_BUSI_PROTO")
#任务[21] 001-01::
V_STEP = V_STEP + 1
sql = """
SELECT CAST(A.CUST_ID AS VARCHAR(32)) AS CUST_ID
,CAST('' AS VARCHAR(20)) AS ORG_ID --插入的空值,包顺龙2017/05/13
,CAST('D002015' AS VARCHAR(20)) AS INDEX_CODE
,CAST(SUM(TAKE_CGT_LINE) AS DECIMAL(22,2)) AS INDEX_VALUE
,CAST(SUBSTR(V_DT, 1, 7) AS VARCHAR(7)) AS YEAR_MONTH
,CAST(V_DT AS DATE) AS ETL_DATE
,CAST(A.CUST_TYP AS VARCHAR(5)) AS CUST_TYPE
,CAST(A.FR_ID AS VARCHAR(5)) AS FR_ID
FROM ACRM_F_CI_ASSET_BUSI_PROTO A
WHERE A.BAL > 0
AND A.LN_APCL_FLG = 'N'
AND(A.PRODUCT_ID LIKE '1010%'
OR A.PRODUCT_ID LIKE '1030%'
OR A.PRODUCT_ID LIKE '1040%'
OR A.PRODUCT_ID LIKE '1050%'
OR A.PRODUCT_ID LIKE '1060%'
OR A.PRODUCT_ID LIKE '1070%'
OR A.PRODUCT_ID LIKE '2010%'
OR A.PRODUCT_ID LIKE '2020%'
OR A.PRODUCT_ID LIKE '2030%'
OR A.PRODUCT_ID LIKE '2040%'
OR A.PRODUCT_ID LIKE '2050%')
GROUP BY A.CUST_ID
,A.CUST_TYP
,A.FR_ID """
sql = re.sub(r"\bV_DT\b", "'"+V_DT10+"'", sql)
ACRM_A_TARGET_D002015 = sqlContext.sql(sql)
ACRM_A_TARGET_D002015.registerTempTable("ACRM_A_TARGET_D002015")
dfn="ACRM_A_TARGET_D002015/"+V_DT+".parquet"
ACRM_A_TARGET_D002015.cache()
nrows = ACRM_A_TARGET_D002015.count()
ACRM_A_TARGET_D002015.write.save(path=hdfs + '/' + dfn, mode='overwrite')
ACRM_A_TARGET_D002015.unpersist()
ACRM_F_CI_ASSET_BUSI_PROTO.unpersist()
ret = os.system("hdfs dfs -rm -r /"+dbname+"/ACRM_A_TARGET_D002015/"+V_DT_LD+".parquet")
et = datetime.now()
print("Step %d start[%s] end[%s] use %d seconds, insert ACRM_A_TARGET_D002015 lines %d") % (V_STEP, st.strftime("%H:%M:%S"), et.strftime("%H:%M:%S"), (et-st).seconds, nrows)
<|fim▁end|> | sqlContext = SQLContext(sc) |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)<|fim▁hole|> run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])<|fim▁end|> | for f in [x.strip() for x in open(argv[1])]: |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
<|fim_middle|>
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | pass |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
<|fim_middle|>
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8 |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
<|fim_middle|>
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v] |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
<|fim_middle|>
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0])) |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
<|fim_middle|>
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_ |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
<|fim_middle|>
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1) |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
<|fim_middle|>
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | raise Exception("Unknown value '%s'" % v) |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
<|fim_middle|>
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | break |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
<|fim_middle|>
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | break |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
<|fim_middle|>
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | headers.mode = pick(value, test_mode_values) |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
<|fim_middle|>
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | headers.is_expr = pick(value, {"normal": False, "expr": True}) |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
<|fim_middle|>
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
<|fim_middle|>
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | raise Exception("unterminated STDOUT header") |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
<|fim_middle|>
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | break |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
<|fim_middle|>
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | raise Exception("Unknown header '%s'" % name) |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
<|fim_middle|>
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | return TestMode.disable |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
<|fim_middle|>
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
<|fim_middle|>
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | return TestMode.fail_compile_parse |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
<|fim_middle|>
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | return TestMode.fail_compile_sem |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
<|fim_middle|>
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | return TestMode.fail_c |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
<|fim_middle|>
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | return TestMode.fail_run |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
<|fim_middle|>
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
<|fim_middle|>
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | pass |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
<|fim_middle|>
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | res = TestMode.pass_ |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
<|fim_middle|>
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | if headers.mode != TestMode.pass_:
res = TestMode.fail_other |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
<|fim_middle|>
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | res = TestMode.fail_other |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
<|fim_middle|>
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1) |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
<|fim_middle|>
<|fim▁end|> | argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1]) |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
<|fim_middle|>
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | print("Usage: %s tests.lst" % argv[0])
sys.exit(1) |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def <|fim_middle|>(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | pick |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def <|fim_middle|>(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | run_test |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def <|fim_middle|>():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def run_tests(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | do_run |
<|file_name|>run_tests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
CC = "gcc"
CFLAGS = "-fmax-errors=4 -std=c99 -pipe -D_POSIX_C_SOURCE=200809L -W -Wall -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-value -Wno-unused-but-set-variable -Wno-unused-function -Wno-main".split(" ")
class Table():
pass
class TestMode():
pass_ = 0
fail_compile_parse = 1
fail_compile_sem = 2
fail_compile_ice = 3
fail_c = 4
fail_run = 5
fail_output = 6
fail_other = 7
disable = 8
test_modes = [TestMode.pass_, TestMode.fail_compile_parse,
TestMode.fail_compile_sem, TestMode.fail_compile_ice,
TestMode.fail_c, TestMode.fail_run, TestMode.fail_output,
TestMode.fail_other, TestMode.disable]
test_mode_names = {
TestMode.pass_: ("pass", "Passed"),
TestMode.fail_compile_parse: ("fail_compile_parse", "Compilation failed (parsing)"),
TestMode.fail_compile_sem: ("fail_compile_sem", "Compilation failed (semantics)"),
TestMode.fail_compile_ice: ("fail_compile_ice", "Compilation failed (ICE)"),
TestMode.fail_c: ("fail_c", "C compilation/linking failed"),
TestMode.fail_run: ("fail_run", "Run failed"),
TestMode.fail_output: ("fail_output", "Output mismatched"),
TestMode.fail_other: ("fail_other", "Expected failure didn't happen"),
TestMode.disable: ("disable", "Disabled"),
}
test_stats = dict([(m, 0) for m in test_modes])
test_mode_values = {}
for m, (s, _) in test_mode_names.iteritems():
test_mode_values[s] = m
def pick(v, m):
if v not in m:
raise Exception("Unknown value '%s'" % v)
return m[v]
def run_test(filename):
testname = os.path.basename(filename)
print("Test '%s'..." % testname)
workdir = tempfile.mkdtemp(prefix="boringtest")
tempfiles = []
src = open(filename)
headers = Table()
headers.mode = TestMode.pass_
headers.is_expr = False
headers.stdout = None
while True:
hline = src.readline()
if not hline:
break
m = re.match("(?://|/\*) ([A-Z]+):(.*)", hline)
if not m:
break
name, value = m.group(1), m.group(2)
value = value.strip()
if name == "TEST":
headers.mode = pick(value, test_mode_values)
elif name == "TYPE":
headers.is_expr = pick(value, {"normal": False, "expr": True})
elif name == "STDOUT":
term = value + "*/"
stdout = ""
while True:
line = src.readline()
if not line:
raise Exception("unterminated STDOUT header")
if line.strip() == term:
break
stdout += line
headers.stdout = stdout
else:
raise Exception("Unknown header '%s'" % name)
src.close()
def do_run():
if headers.mode == TestMode.disable:
return TestMode.disable
# make is for fags
tc = os.path.join(workdir, "t.c")
tcf = open(tc, "w")
tempfiles.append(tc)
res = subprocess.call(["./main", "cg_c", filename], stdout=tcf)
tcf.close()
if res != 0:
if res == 1:
return TestMode.fail_compile_parse
if res == 2:
return TestMode.fail_compile_sem
return TestMode.fail_compile_ice
t = os.path.join(workdir, "t")
tempfiles.append(t)
res = subprocess.call([CC] + CFLAGS + [tc, "-o", t])
if res != 0:
return TestMode.fail_c
p = subprocess.Popen([t], stdout=subprocess.PIPE)
output, _ = p.communicate()
res = p.wait()
if res != 0:
return TestMode.fail_run
if headers.stdout is not None and headers.stdout != output:
print("Program output: >\n%s<\nExpected: >\n%s<" % (output,
headers.stdout))
return TestMode.fail_output
return TestMode.pass_
actual_res = do_run()
for f in tempfiles:
try:
os.unlink(f)
except OSError:
pass
os.rmdir(workdir)
res = actual_res
if res == TestMode.disable:
pass
elif res == headers.mode:
res = TestMode.pass_
else:
if headers.mode != TestMode.pass_:
res = TestMode.fail_other
test_stats[res] += 1
print("Test '%s': %s (expected %s, got %s)" % (testname,
test_mode_names[res][0], test_mode_names[headers.mode][0],
test_mode_names[actual_res][0]))
def <|fim_middle|>(list_file_name):
base = os.path.dirname(list_file_name)
for f in [x.strip() for x in open(argv[1])]:
run_test(os.path.join(base, f))
print("SUMMARY:")
test_sum = 0
for m in test_modes:
print(" %s: %d" % (test_mode_names[m][1], test_stats[m]))
test_sum += test_stats[m]
passed_tests = test_stats[TestMode.pass_]
failed_tests = test_sum - passed_tests - test_stats[TestMode.disable]
print("Passed/failed: %s/%d" % (passed_tests, failed_tests))
if failed_tests:
print("OMG OMG OMG ------- Some tests have failed ------- OMG OMG OMG")
sys.exit(1)
if __name__ == "__main__":
argv = sys.argv
if len(argv) != 2:
print("Usage: %s tests.lst" % argv[0])
sys.exit(1)
#subprocess.check_call(["make", "main"])
run_tests(argv[1])
<|fim▁end|> | run_tests |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
<|fim▁hole|> else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64<|fim▁end|> | self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm) |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
<|fim_middle|>
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
<|fim_middle|>
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
<|fim_middle|>
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data) |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
<|fim_middle|>
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
) |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
<|fim_middle|>
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
<|fim_middle|>
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | name = "sha1"
digest_size = 20
block_size = 64 |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
<|fim_middle|>
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | name = "sha224"
digest_size = 28
block_size = 64 |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
<|fim_middle|>
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | name = "sha256"
digest_size = 32
block_size = 64 |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
<|fim_middle|>
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | name = "sha384"
digest_size = 48
block_size = 128 |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
<|fim_middle|>
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | name = "sha512"
digest_size = 64
block_size = 128 |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
<|fim_middle|>
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | name = "ripemd160"
digest_size = 20
block_size = 64 |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
<|fim_middle|>
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | name = "whirlpool"
digest_size = 64
block_size = 64 |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
<|fim_middle|>
<|fim▁end|> | name = "md5"
digest_size = 16
block_size = 64 |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
<|fim_middle|>
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
) |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
<|fim_middle|>
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | raise TypeError("Expected instance of interfaces.HashAlgorithm.") |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
<|fim_middle|>
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | self._ctx = self._backend.create_hash_ctx(self.algorithm) |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
<|fim_middle|>
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | self._ctx = ctx |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
<|fim_middle|>
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | raise AlreadyFinalized("Context was already finalized.") |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
<|fim_middle|>
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | raise TypeError("data must be bytes.") |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
<|fim_middle|>
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | raise AlreadyFinalized("Context was already finalized.") |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
<|fim_middle|>
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | raise AlreadyFinalized("Context was already finalized.") |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def <|fim_middle|>(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | __init__ |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def <|fim_middle|>(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def copy(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | update |
<|file_name|>hashes.py<|end_file_name|><|fim▁begin|># This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HashBackend
from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
if not isinstance(backend, HashBackend):
raise UnsupportedAlgorithm(
"Backend object does not implement HashBackend.",
_Reasons.BACKEND_MISSING_INTERFACE
)
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self._algorithm = algorithm
self._backend = backend
if ctx is None:
self._ctx = self._backend.create_hash_ctx(self.algorithm)
else:
self._ctx = ctx
algorithm = utils.read_only_property("_algorithm")
def update(self, data):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._ctx.update(data)
def <|fim_middle|>(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return Hash(
self.algorithm, backend=self._backend, ctx=self._ctx.copy()
)
def finalize(self):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
digest = self._ctx.finalize()
self._ctx = None
return digest
@utils.register_interface(interfaces.HashAlgorithm)
class SHA1(object):
name = "sha1"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA224(object):
name = "sha224"
digest_size = 28
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA256(object):
name = "sha256"
digest_size = 32
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class SHA384(object):
name = "sha384"
digest_size = 48
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class SHA512(object):
name = "sha512"
digest_size = 64
block_size = 128
@utils.register_interface(interfaces.HashAlgorithm)
class RIPEMD160(object):
name = "ripemd160"
digest_size = 20
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class Whirlpool(object):
name = "whirlpool"
digest_size = 64
block_size = 64
@utils.register_interface(interfaces.HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16
block_size = 64
<|fim▁end|> | copy |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.