示例#1
0
        if group is None:
            database.save_group(guild_name, guild_id)
            group = database.fetch_group_by_dgroup_id(guild_id)

        assert (group is not None)
        database.save_advert(subm.fullname, subm.permalink, group['id'],
                             subm.created_utc)


print('Connecting to database')
database.connect(config.database_file)
database.create_missing_tables()
database.prune()

print('Fetching lists')
blacklist = StringList('blacklist.txt')
whitelist = StringList('whitelist.txt')

print('Logging in')
reddit = praw.Reddit(client_id=auth_config.client_id,
                     client_secret=auth_config.client_secret,
                     password=auth_config.password,
                     user_agent='DiscordServers bot by /u/tjstretchalot',
                     username=auth_config.username)

subreddit = reddit.subreddit(config.subreddit_name)
recently_checked_subm_ids = []
hot_check_counter = 0
last_prune_time = time.time()

# CHECK SUBREDDIT FLAIRS BEFORE STARTING
示例#2
0
 def setUp(self):
     from stringlist import StringList
     self.sl = StringList('hello', 'world')
示例#3
0
class TestStringList_StartWithString(unittest.TestCase):
    """
    Test basic functionality of a StringList when the initial value is a 
    string.
    """

    def setUp(self):
        from stringlist import StringList
        self.sl = StringList('hello world')
        self.sl2 = StringList()
        
    def test_empty_stringlist(self):
        """
        What happens when a StringList is initialized with no parameters?
        """
        self.assertEquals(self.sl2, "")
        self.sl2 += 'foo'
        self.assertEquals(self.sl2, "foo")
    
    def test_empty_stringlist_convert(self):
        """
        What happens when a StringList is initialized with no parameters and append() is called?
        """
        self.sl2.append('foo')
        self.assertEquals(self.sl2, ['foo'])
    

    def test_string_split(self):
        """
        Does split() work as expected?
        """
        self.assertEquals(self.sl.split(' '), ['hello', 'world'])
        
    def test_string_array(self):
        """
        Do the string index/slice methods work?
        """
        self.assertEquals(self.sl[1:3], 'el')
        self.assertEquals(self.sl[0], 'h')
        
    def test_string_addition(self):
        """
        Can we add two stringlist objects together, if they are strings?
        """
        new_sl = self.sl + " wow!"
        
        self.assertEquals(new_sl, "hello world wow!")
        
        # make sure the original property isn't altered.
        self.assertEquals(self.sl, "hello world")
        
    def test_string_iaddition(self):
        """
        Can we do an inline addition of another string?
        """
        self.sl += " zoinks!"
        
        self.assertEquals(self.sl, "hello world zoinks!")
        
    def test_string_conversion(self):
        """
        Convert from a string to an array
        """
        self.sl.append('foo bar')
        
        self.assertEquals(self.sl, ['hello world', 'foo bar'])
        
    def test_iteration(self):
        """
        Use the StringList in a loop
        """
        output = []
        
        for x in self.sl:
            output.append(x)
        
        self.assertEquals(output, ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'])
        
        self.assertEquals([x for x in self.sl], ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'])
        
    def test_contains(self):
        """
        Does x in StringList work?
        """
        self.assertTrue('e' in self.sl)
        self.assertFalse('x' in self.sl)
        
    def test_delete(self):
        """
        Test del StringList[x] - should raise an exception
        """
        with self.assertRaises(TypeError):
            del self.sl[1]
            
    def test_index_assignment(self):
        """
        Test StringList[x] = 'c' - should raise an exception
        """
        with self.assertRaises(TypeError):
            self.sl[1] = 'd'
       
    def test_length(self):
        """
        len(StringList)
        """
        self.assertEquals(len(self.sl), 11)
        
    def test_inline_addition_integer(self):
        """
        StringList += 100
        """
        with self.assertRaises(TypeError):
            self.sl += 100
        
    def test_addition_object(self):
        """
        StringList + 100
        """
        with self.assertRaises(TypeError):
            new_sl = self.sl + 100
            
    def test_cast_to_string(self):
        """
        str(StringList)
        """
        self.assertEquals(str(self.sl), "'hello world'")
示例#4
0
class TestStringList_StartWithList(unittest.TestCase):
    """
    Test basic functionality of a StringList when the initial value is a series
    of strings.
    """

    def setUp(self):
        from stringlist import StringList
        self.sl = StringList('hello', 'world')
        
    def test_getitem_slice(self):
        """
        Does index and slice access work?
        """
        self.assertEquals(self.sl[0], 'hello')
        self.assertEquals(self.sl[:-1], ['hello'])
        
    def test_pop(self):
        """
        Does a common function proxy properly?
        """
        self.sl.pop()
        
        self.assertEquals(self.sl, ['hello'])
        
    def test_addition_string(self):
        """
        Does StringList + a string work?
        """
        new_sl = self.sl + 'foo'
        
        self.assertEquals(new_sl, ['hello', 'world', 'foo'])
        
        # make sure the original property isn't altered.
        self.assertEquals(self.sl, ['hello', 'world'])
        
    def test_addition_list(self):
        """
        Does StringList += a list work?
        """
        new_sl = self.sl + ['foo', 'bar']
        
        self.assertEquals(new_sl, ['hello', 'world', 'foo', 'bar'])
        
        # make sure the original property isn't altered.
        self.assertEquals(self.sl, ['hello', 'world'])
        
    def test_inline_addition_string(self):
        """
        Does StringList += a string work?
        """
        self.sl += 'foo'
        
        self.assertEquals(self.sl, ['hello', 'world', 'foo'])
        
    def test_inline_addition_list(self):
        """
        Does StringList += a list work?
        """
        self.sl += ['foo', 'bar']
        
        self.assertEquals(self.sl, ['hello', 'world', 'foo', 'bar'])
        
    def test_iteration(self):
        """
        Can you loop over a StringList?
        """
        output = []
        
        for x in self.sl:
            output.append(x)
            
        self.assertEquals(output, ['hello', 'world'])
            
        self.assertEquals([x for x in self.sl], ['hello', 'world'])
        
    def test_contains(self):
        """
        Does x in StringList work?
        """
        self.assertTrue('hello' in self.sl)
        self.assertFalse('foo' in self.sl)
        
    def test_delete(self):
        """
        Test del StringList[x]
        """
        del self.sl[0]
        
        self.assertEquals(self.sl, ['world'])
        
    def test_index_assignment(self):
        """
        Test StringList[x] = 'string'
        """
        self.sl[1] = 'foo'
        
        self.assertEquals(self.sl, ['hello', 'foo'])
        
    def test_length(self):
        """
        len(StringList)
        """
        self.assertEquals(len(self.sl), 2)
        
        
    def test_inline_addition_integer(self):
        """
        StringList += 100
        """
        self.sl += 100
            
        self.assertEquals(self.sl, ['hello', 'world', 100])
        
    def test_addition_object(self):
        """
        StringList + 100
        """
        new_sl = self.sl + 100
        
        self.assertEquals(new_sl, ['hello', 'world', 100])
        
        self.assertEquals(self.sl, ['hello', 'world'])
            
    def test_cast_to_string(self):
        """
        str(StringList)
        """
        self.assertEquals(str(self.sl), "['hello', 'world']")