def processLines(f, dictionaries):
    dict = {}
    lineCount = 0
    for line in f:
        #Ignoring header (first line) if needed.
        if lineCount == 0:
            lineCount += 1
            if ignoreHeader:
                continue
        columns = columnsMask.lower().split(separator)
        values = line.split(separator)

        for column in columns:
            column = Utilities.sanitise(column.lower())

            #meaningless columns defined by 'null' or empty value
            if column == "null" or column == "":
                continue

            if len(values) <= columns.index(column):
                dict[column] = ""
            else:
                dict[column] = Utilities.sanitise(
                    values[columns.index(column)])

        #'name' and 'classname' are mandatory. Ignoring lines without any of these fields.
        if not (dict["name"] == "" or dict["classname"] == ""
                or dict["status"] == ""):
            if dict["classname"] in dictionaries:
                dictionaries[dict["classname"]].append(dict.copy())
            else:
                dictionaries[dict["classname"]] = []
                dictionaries[dict["classname"]].append(dict.copy())
Esempio n. 2
0
 def test_ConvertIngredientInDifferentCategoryUnit(self):
     ing = Models.RecipeIngredient(name='Flour', amount='10', unit='tbsps')
     # convert to ounces
     converted = RecipeOperations.RecipeOperations.convertIngredientToUnit(
         ing, 'oz')
     convertedAmount = Utilities.convert_to_float(converted.amount)
     self.assertAlmostEqual(2.65, round(convertedAmount, 2))
Esempio n. 3
0
 def fromInt(i):
     Utilities.checkRange(i, 1, 8)
     if i == 1 :
         return EnumWeekday.MONDAY
     elif i == 2 :
         return EnumWeekday.TUESDAY
     elif i == 3 :
         return EnumWeekday.WEDNESDAY
     elif i == 4 :
         return EnumWeekday.THURSDAY
     elif i == 5 :
         return EnumWeekday.FRIDAY
     elif i == 6 :
         return EnumWeekday.SATURDAY
     elif i == 7 :
         return EnumWeekday.SUNDAY
Esempio n. 4
0
 def fromInt(i):
     Utilities.checkRange(i, 1, 8)
     if i == 1:
         return EnumWeekday.MONDAY
     elif i == 2:
         return EnumWeekday.TUESDAY
     elif i == 3:
         return EnumWeekday.WEDNESDAY
     elif i == 4:
         return EnumWeekday.THURSDAY
     elif i == 5:
         return EnumWeekday.FRIDAY
     elif i == 6:
         return EnumWeekday.SATURDAY
     elif i == 7:
         return EnumWeekday.SUNDAY
Esempio n. 5
0
 def test_ConvertIngredientInDifferentCategoryBase(self):
     ing = Models.RecipeIngredient(name='Flour', amount='1 1/2', unit='c')
     # convert to grams
     converted = RecipeOperations.RecipeOperations.convertIngredientToUnit(
         ing, 'g')
     convertedAmount = Utilities.convert_to_float(converted.amount)
     self.assertAlmostEqual(180, round(convertedAmount))
Esempio n. 6
0
 def test_bubblesort_with_array(
         self):  #function to test bubble_sort with array
     result = Utilities.bubble_sort([12, 1, 0, 5, 4, 2])
     expected = [0, 1, 2, 4, 5, 2]  #
     self.assertNotEqual(
         expected,
         result)  # Checking result and expected With NotEqual Function
Esempio n. 7
0
 def test_tempconverTrue(
         self):  #function to test temperature conversion in Celcius
     result = Utilities.Temp_conversion(2100, 0)  #storing the result
     expected = 1148.888888888889
     self.assertTrue(
         expected,
         result)  # Checking result and expected With True Function
Esempio n. 8
0
 def test_tempconverFalse(
         self):  #function to test temperature conversion in Farheiniet
     result = Utilities.Temp_conversion(1148.888888888889,
                                        1)  #storing the result
     expected = 2100
     self.assertTrue(
         expected,
         result)  # Checking result and expected With True Function
Esempio n. 9
0
 def test_bubblesort_with_True(
         self):  # function to test bubble sort with True
     result = Utilities.bubble_sort([12, 1, 0, 5, 4, 2]), [
         0, 1, 2, 4, 5, 12
     ]  # call the utilities class and storing the result
     expected = True
     self.assertTrue(
         expected,
         result)  # Checking result and expected With True Function
Esempio n. 10
0
 def test_bubblesort_with_possitive_array(
         self):  # function to test bubble sort with positive numbers
     result = Utilities.bubble_sort(
         [12, 1, 0, 5, 4,
          2])  # call the utilities class and storing the result
     expected = [0, 1, 2, 4, 5, 12]
     self.assertEqual(
         expected,
         result)  # Checking result and expected With Equal Function
Esempio n. 11
0
 def test_ConvertIngredientInSameCategory(self):
     ing = Models.RecipeIngredient(name='Test Ingredient',
                                   amount='1 1/2',
                                   unit='cups')
     # convert to tbsp
     converted = RecipeOperations.RecipeOperations.convertIngredientToUnit(
         ing, 'tbsp')
     convertedAmount = Utilities.convert_to_float(converted.amount)
     self.assertAlmostEqual(24, round(convertedAmount))
Esempio n. 12
0
ignoreHeader = args.ignoreheader
isVerbose = args.verbose
mandatoryColumns = ["name", "status", "classname"]


# Print something to console
def printToConsole(obj):
    if isVerbose:
        print str(obj)


########## STEP 1. Check column mask for mandatory columns ##########
printToConsole("\nChecking the list of columns. Mandatory columns are:")
for column in mandatoryColumns:
    printToConsole("\t - " + column)
if not Utilities.checkColumnMask(columnsMask, separator, mandatoryColumns):
    quit()
print "\nList of columns is valid"

########## STEP 2. Parse files (or pipe input) into dictionary object ##########


# Process a single line
def processLines(f, dictionaries):
    dict = {}
    lineCount = 0
    for line in f:
        #Ignoring header (first line) if needed.
        if lineCount == 0:
            lineCount += 1
            if ignoreHeader:
 def test_dayofWeekFalse(self):  #function to test daysofWeek
     result = Utilities.dayofWeek(14, 6, 2019)  #storing the result
     expected = False
     self.assertFalse(
         expected,
         result)  #Checking result and expected With False Function
Esempio n. 14
0
 def test_monthlypayment(self):  #function to test monthly payment
     result = Utilities.calculatePayment(1200, 1, 13)  # storing the result
     expected = 107.18073085409955
     self.assertTrue(
         expected,
         result)  # Checking result and expected With True Function
Esempio n. 15
0
 def __checkParam(name, tRanges):
     Utilities.checkInstanceString(name)
Esempio n. 16
0
 def __init__(self, day):
     Utilities.checkRange(day, 1, 8)
     self.day = day;
 def test_dayofWeekTrue(self):  #function to test daysofWeek
     result = Utilities.dayofWeek(14, 6, 2019)  #storing the result
     expected = "Friday"
     self.assertTrue(
         expected, result)  #Checking result and expected With True Function
Esempio n. 18
0
 def __checkParam(title, dept, num, sectX, tRanges, sln, description):
     Utilities.checkInstanceString(title)
     Utilities.checkInstanceString(dept)
     Utilities.checkRange(num, 100, 1000)
     Utilities.checkInstanceString(sectX)
     Utilities.checkInstanceString(description)
     # check tRanges later TODO
     Utilities.checkRange(sln, 0, 1000000)
Esempio n. 19
0
 def __checkParam(name, tRanges):
     Utilities.checkInstanceString(name)
Esempio n. 20
0
 def __checkParam(title, dept, num, sectX, tRanges, sln, description):
     Utilities.checkInstanceString(title)
     Utilities.checkInstanceString(dept)
     Utilities.checkRange(num, 100, 1000)
     Utilities.checkInstanceString(sectX)
     Utilities.checkInstanceString(description)
     # check tRanges later TODO
     Utilities.checkRange(sln, 0, 1000000)
Esempio n. 21
0
 def testinsertion_sort_with_negative(self):
     result = (Utilities.insertionSort([-1, 6, 5, 0, -1, -6]))
     expected = [-6, -1, -1, 0, 5, 6]
     self.assertEqual(expected, result)  # Checking result and expected With Equal Function
Esempio n. 22
0
 def __init__(self, day):
     Utilities.checkRange(day, 1, 8)
     self.day = day
Esempio n. 23
0
 def testinsertion_sort_with_negative_num(self):  # function to test insertion sort with array of -ve numbers
     result = (Utilities.insertionSort([-1, 2, -2, 0, -1, -6]))
     expected = [-6, 0, -1, -1, 0, 2]
     self.assertNotEqual(expected, result)  # Checking result and expected With NotEqual Function
 def testpalindromeFalse(self):
     result = Utilities.Is_palindrome('am')
     expected = False
     self.assertTrue(expected, result)
Esempio n. 25
0
 def testinsertionsort_with_possitive_num(self):  # function to test insertion sort with array of +ve numbers
     result = (Utilities.insertionSort([12, 5, 45, 78, 1, 0]))  # Pass Array To Insertion Sort Function
     expected = [0, 1, 5, 12, 45, 78]  # Initialize Expected as Sorted Array
     self.assertEqual(expected, result)  # Checking result and expected With Equal Function
 def testpalindromeTrue(self):
     result = Utilities.Is_palindrome('mam')
     expected = True
     self.assertTrue(expected, result)
Esempio n. 27
0
 def test_monthlypaymentNotequal(self):  #function to test monthly payment
     result = Utilities.calculatePayment(1200, 2, 13)  # storing the result
     expected = 17.18073085409955
     self.assertNotEqual(
         expected,
         result)  # Checking result and expected With NotEqual Function
Esempio n. 28
0
 def testbinary_search_possitive(self):                         # function to test binarysearch of posotive number
     result = Utilities.binary_search(1,4,3,[1,2,3,4,5,6])      # call the uitlites class and storing the result
     expected = 1
     self.assertEqual(expected, result)                         # Checking result and expected With Equal Function