def get_my_nodes():
	"""Get nodes assigned to this host for computation
	"""
	if not os.path.exists("/etc/cluster-hosts"):
		raise Exception("No cluster hosts specified")

	#grab list of hosts in cluster, in order
	hosts = []
	with open("/etc/cluster-hosts", "r") as fp:
		for line in fp:
			hosts.append(line.strip())

	d = Differ()
	diffnodes = list(d.get_nodes())
	
	#compute node->host assignments (round-robin)
	assigns = dict()
	dx = 0
	for item in diffnodes:
		assigns[item] = hosts[dx % len(hosts)]
		dx += 1

	myitems = []
	fqdn = socket.getfqdn()
	for (item, host) in assigns.items():
		if host == fqdn:
			myitems.append(item)
	return myitems
예제 #2
0
 def test_one_surplus_row(self):
     computed = [['anna', 'lotr'],
                 ['luke', 'lotr']]
     expected = [['anna', 'shrek']]
     
     differ = Differ(compare, [str,str])
     differ.match(expected, computed, 0)
     self.assertEqual(differ.missing, [])
     self.assertEqual(differ.surplus, [['luke', 'lotr']])
예제 #3
0
 def test_build_nonstandard(self):
     standard = Model("standard.txt")
     p = Proover(standard)
     pairs = [(symbols('x1, x2'))]
     proof = p.build_and_test(pairs)
     differ = Differ(Processors(), standard, proof)
     diff = differ.diff()
     self.assertEqual(0, len(diff[0]))
     self.assertEqual(1, len(diff[1]))
     self.assertEqual(0, len(diff[2]))
     self.assertEqual(0, len(diff[3]))
     self.assertEqual(0, len(diff[4]))
     self.assertEqual(0, len(diff[5]))
예제 #4
0
 def test_two_rows_with_difference(self):
     '''See fitbook Figure 5.3'''
     computed = [['anna', 'lotr'],
                 ['luke', 'lotr']]
     expected = [[Cell('anna'), Cell('shrek')],
                 [Cell('luke'), Cell('lotr')]]
     
     cell = expected[0][1]
     desc = [str ,str]
     #differ = Differ(compare, desc)
     differ = Differ(compare, desc)
     differ.match(expected, computed, 0)
     cell = expected[0][1]
     #print 'missing : %s' % differ.missing
     #print 'surplus : %s' % differ.surplus
     #print expected
     self.assertEqual(cell.expected, 'shrek')
예제 #5
0
파일: RowFixture.py 프로젝트: epronk/stuff
class RowFixture(object):
    def collect(self):
        result = self.query()
        out_result = []

        for row in result:
            if type(row) == dict:
                x = [row.get(attr) for attr in self.column_names]
            else:
                for attr in self.column_names:
                    pass
                    #print string.replace(attr, ' ', '_')
                x = [getattr(row, string.replace(attr, ' ', '_')) for attr in self.column_names]
                
            out_result.append(x)
        return out_result
        
    def process(self, table):
        self.column_names = [str(x) for x in table.rows[1]]
        computed = self.collect()
        expected_values = table.rows[2:]

        def compare_row2(expected_values,calculated):
            print 'compare_row'
            for expected_value, calculated_value in zip(expected_values, calculated):
                self.engine.compare(expected_value, calculated_value)

        if len(computed):
            desc = []
            for cell in computed[0]:
                desc.append(type(cell))
        else:
            desc = []
            for cell in table.rows[1]:
                desc.append(str)
        self.differ = Differ(compare_row2, desc)
        self.differ.match(expected_values, computed, 0)
        for row in self.differ.missing:
            row[0].missing()
        for row in self.differ.surplus:
            table.append_row(row)
예제 #6
0
    def test_Diffs(self):
        differ = Differ()

        #Test equal content
        differ.left = validJSON
        differ.right = validJSON
        self.assertIn("left and right are equal", differ.Diff(), "Expected equal content")

        #Test diff size
        differ.left = validJSON
        differ.right = validJSONDiffSize
        self.assertIn("sizes are different", differ.Diff(), "Expected different size")

        #Test same size diff contents
        differ.left = validJSON
        differ.right = validJSON2
        self.assertIn("Sizes are equal but contents different", differ.Diff(), "Expected different contents")
        self.assertIn("offset", differ.Diff(), "Expected different contents")
예제 #7
0
파일: RowFixture.py 프로젝트: epronk/pyfit2
    def process(self, table):
        self.column_names = [str(x) for x in table.rows[1]]
        computed = self.collect()
        expected_values = table.rows[2:]

        def compare_row2(expected_values,calculated):
            for expected_value, calculated_value in zip(expected_values, calculated):
                self.engine.compare(expected_value, calculated_value)

        if len(computed):
            desc = []
            for cell in computed[0]:
                desc.append(type(cell))
        else:
            desc = []
            for cell in table.rows[1]:
                desc.append(str)
        self.differ = Differ(compare_row2, desc)
        self.differ.match(expected_values, computed, 0)
        for row in self.differ.missing:
            row[0].missing()
        for row in self.differ.surplus:
            table.append_row(row)
예제 #8
0
    def test_ValidJSONs(self):
        differ = Differ()

        #Empty jsons must fail the validation
        self.assertEqual(differ.isLeftValid(),"false", "Expected left invalid when empty")
        self.assertEqual(differ.isRightValid(), "false", "Expected right invalid when empty")

        #Invalid jsons must fail the validation
        differ.left = invalidJSON
        differ.right = invalidJSON
        self.assertEqual(differ.isLeftValid(), "false", "Expected left invalid")
        self.assertEqual(differ.isRightValid(), "false", "Expected right invalid")

        #Valid jsons must pass the validation
        differ.left = validJSON
        differ.right = validJSON
        self.assertEqual(differ.isLeftValid(), "true", "Expected left valid")
        self.assertEqual(differ.isRightValid(), "true", "Expected right valid")
예제 #9
0
    def test_getState(self):

        differ = Differ()

        differ.left=""
        differ.right=""
        self.assertEqual(differ.getState(), "22", "Expected getState 22")

        differ.left=""
        differ.right=invalidJSON
        self.assertEqual(differ.getState(), "21", "Expected getState 21")

        differ.left=""
        differ.right=validJSON
        self.assertEqual(differ.getState(), "20", "Expected getState 20")

        differ.left=invalidJSON
        differ.right=""
        self.assertEqual(differ.getState(), "12", "Expected getState 12")

        differ.left=invalidJSON
        differ.right=invalidJSON
        self.assertEqual(differ.getState(),"11", "Expected getState 11")

        differ.left=invalidJSON
        differ.right=validJSON
        self.assertEqual(differ.getState(),"10", "Expected getState 10")

        differ.left=validJSON
        differ.right=""
        self.assertEqual(differ.getState(),"02", "Expected getState 02")

        differ.left=validJSON
        differ.right=invalidJSON
        self.assertEqual(differ.getState(), "01", "Expected getState 01")

        differ.left=validJSON
        differ.right=validJSON
        self.assertEqual(differ.getState(), "00", "Expected getState 00")
예제 #10
0
def main() -> None:
    x, y = read_data(filename)

    h = 1.0

    Differ.print_init("X              :", x)
    Differ.print_init("Y              :", y)
    Differ.print_res("Onesided       :", Differ.left(y, h))
    Differ.print_res("Center         :", Differ.center(y, h))
    Differ.print_res("Second Range   :", Differ.second_runge(y, h, 1))
    Differ.print_res("Aligned params :", Differ.aligned_coeffs(x, y))
    Differ.print_res("Second oneSided:", Differ.second_left(y, h))