<s> from __future__ import unicode_literals <EOL> import os <EOL> import sys <EOL> import unittest <EOL> import tempfile <EOL> import shutil <EOL> import textwrap <EOL> import sqlite3 <EOL> import StringIO <EOL> from billy . scripts import initializedb <EOL> class TestInitializedb ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . temp_dir = tempfile . mkdtemp ( ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . temp_dir ) <EOL> def test_usage ( self ) : <EOL> filename = '<STR_LIT>' <EOL> old_stdout = sys . stdout <EOL> usage_out = StringIO . StringIO ( ) <EOL> sys . stdout = usage_out <EOL> try : <EOL> with self . assertRaises ( SystemExit ) : <EOL> initializedb . main ( [ filename ] ) <EOL> finally : <EOL> sys . stdout = old_stdout <EOL> expected = textwrap . dedent ( """<STR_LIT>""" ) <EOL> self . assertMultiLineEqual ( usage_out . getvalue ( ) , expected ) <EOL> def test_main ( self ) : <EOL> cfg_path = os . path . join ( self . temp_dir , '<STR_LIT>' ) <EOL> with open ( cfg_path , '<STR_LIT>' ) as f : <EOL> f . write ( textwrap . dedent ( """<STR_LIT>""" ) ) <EOL> alembic_path = os . path . join ( self . temp_dir , '<STR_LIT>' ) <EOL> with open ( alembic_path , '<STR_LIT>' ) as f : <EOL> f . write ( textwrap . dedent ( """<STR_LIT>""" ) ) <EOL> initializedb . main ( [ initializedb . __file__ , cfg_path , alembic_path ] ) <EOL> sqlite_path = os . path . join ( self . temp_dir , '<STR_LIT>' ) <EOL> self . assertTrue ( os . path . exists ( sqlite_path ) ) <EOL> conn = sqlite3 . connect ( sqlite_path ) <EOL> cursor = conn . cursor ( ) <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> tables = [ row [ <NUM_LIT:0> ] for row in cursor . fetchall ( ) ] <EOL> self . assertEqual ( set ( tables ) , set ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) ) <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> version = cursor . fetchone ( ) [ <NUM_LIT:0> ] <EOL> self . assertNotEqual ( version , None ) </s>
